source: trip-planner-front/node_modules/log4js/lib/appenders/adapters.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[6a3a178]1function maxFileSizeUnitTransform(maxLogSize) {
2 if (typeof maxLogSize === 'number' && Number.isInteger(maxLogSize)) {
3 return maxLogSize;
4 }
5
6 const units = {
7 K: 1024,
8 M: 1024 * 1024,
9 G: 1024 * 1024 * 1024,
10 };
11 const validUnit = Object.keys(units);
12 const unit = maxLogSize.substr(maxLogSize.length - 1).toLocaleUpperCase();
13 const value = maxLogSize.substring(0, maxLogSize.length - 1).trim();
14
15 if (validUnit.indexOf(unit) < 0 || !Number.isInteger(Number(value))) {
16 throw Error(`maxLogSize: "${maxLogSize}" is invalid`);
17 } else {
18 return value * units[unit];
19 }
20}
21
22function adapter(configAdapter, config) {
23 const newConfig = Object.assign({}, config);
24 Object.keys(configAdapter).forEach((key) => {
25 if (newConfig[key]) {
26 newConfig[key] = configAdapter[key](config[key]);
27 }
28 });
29 return newConfig;
30}
31
32function fileAppenderAdapter(config) {
33 const configAdapter = {
34 maxLogSize: maxFileSizeUnitTransform
35 };
36 return adapter(configAdapter, config);
37}
38
39const adapters = {
40 file: fileAppenderAdapter,
41 fileSync: fileAppenderAdapter
42};
43
44module.exports.modifyConfig = config => (adapters[config.type] ? adapters[config.type](config) : config);
Note: See TracBrowser for help on using the repository browser.