source: trip-planner-front/node_modules/log4js/lib/appenders/dateFile.js

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

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1const streams = require('streamroller');
2const os = require('os');
3
4const eol = os.EOL;
5
6/**
7 * File appender that rolls files according to a date pattern.
8 * @filename base filename.
9 * @pattern the format that will be added to the end of filename when rolling,
10 * also used to check when to roll files - defaults to '.yyyy-MM-dd'
11 * @layout layout function for log messages - defaults to basicLayout
12 * @timezoneOffset optional timezone offset in minutes - defaults to system local
13 */
14function appender(
15 filename,
16 pattern,
17 layout,
18 options,
19 timezoneOffset
20) {
21 // the options for file appender use maxLogSize, but the docs say any file appender
22 // options should work for dateFile as well.
23 options.maxSize = options.maxLogSize;
24
25 const logFile = new streams.DateRollingFileStream(
26 filename,
27 pattern,
28 options
29 );
30
31 logFile.on("drain", () => {
32 process.emit("log4js:pause", false);
33 });
34
35 const app = function (logEvent) {
36 if (!logFile.write(layout(logEvent, timezoneOffset) + eol, "utf8")) {
37 process.emit("log4js:pause", true);
38 }
39 };
40
41 app.shutdown = function (complete) {
42 logFile.write('', 'utf-8', () => {
43 logFile.end(complete);
44 });
45 };
46
47 return app;
48}
49
50function configure(config, layouts) {
51 let layout = layouts.basicLayout;
52
53 if (config.layout) {
54 layout = layouts.layout(config.layout.type, config.layout);
55 }
56
57 if (!config.alwaysIncludePattern) {
58 config.alwaysIncludePattern = false;
59 }
60
61 return appender(
62 config.filename,
63 config.pattern,
64 layout,
65 config,
66 config.timezoneOffset
67 );
68}
69
70module.exports.configure = configure;
Note: See TracBrowser for help on using the repository browser.