@@ -36,49 +36,49 @@ npm install log4js
36
36
## usage
37
37
38
38
Minimalist version:
39
-
40
- var log4js = require('log4js');
41
- var logger = log4js.getLogger();
42
- logger.debug("Some debug messages");
43
-
39
+ ``` javascript
40
+ var log4js = require (' log4js' );
41
+ var logger = log4js .getLogger ();
42
+ logger .debug (" Some debug messages" );
43
+ ```
44
44
By default, log4js outputs to stdout with the coloured layout (thanks to [ masylum] ( http://github.com/masylum ) ), so for the above you would see:
45
45
46
46
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
47
47
48
48
See example.js for a full example, but here's a snippet (also in fromreadme.js):
49
-
50
- var log4js = require('log4js');
51
- //console log is loaded by default, so you won't normally need to do this
52
- //log4js.loadAppender('console');
53
- log4js.loadAppender('file');
54
- //log4js.addAppender(log4js.appenders.console());
55
- log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
56
-
57
-
8000
var logger = log4js.getLogger('cheese');
58
- logger.setLevel('ERROR');
59
-
60
- logger.trace('Entering cheese testing');
61
- logger.debug('Got cheese.');
62
- logger.info('Cheese is Gouda.');
63
- logger.warn('Cheese is quite smelly.');
64
- logger.error('Cheese is too ripe!');
65
- logger.fatal('Cheese was breeding ground for listeria.');
66
-
49
+ ``` javascript
50
+ var log4js = require (' log4js' );
51
+ // console log is loaded by default, so you won't normally need to do this
52
+ // log4js.loadAppender('console');
53
+ log4js .loadAppender (' file' );
54
+ // log4js.addAppender(log4js.appenders.console());
55
+ log4js .addAppender (log4js .appenders .file (' logs/cheese.log' ), ' cheese' );
56
+ ` ` ` javascript
57
+ var logger = log4js.getLogger('cheese');
58
+ logger.setLevel('ERROR');
59
+
60
+ logger.trace('Entering cheese testing');
61
+logger.debug('Got cheese.');
62
+ logger.info('Cheese is Gouda.');
63
+ logger.warn('Cheese is quite smelly.');
64
+ logger.error('Cheese is too ripe!');
65
+ logger.fatal('Cheese was breeding ground for listeria.');
66
+ ` ` `
67
67
Output:
68
68
69
69
[2010 - 01 - 17 11 : 43 : 37.987 ] [ERROR ] cheese - Cheese is too ripe!
70
70
[2010 - 01 - 17 11 : 43 : 37.990 ] [FATAL ] cheese - Cheese was breeding ground for listeria.
71
71
72
72
The first 5 lines of the code above could also be written as:
73
-
74
- var log4js = require('log4js');
75
- log4js.configure({
76
- appenders: [
77
- { type: 'console' },
78
- { type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
79
- ]
80
- });
81
-
73
+ ` ` ` javascript
74
+ var log4js = require('log4js');
75
+ log4js.configure({
76
+ appenders: [
77
+ { type: 'console' },
78
+ { type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
79
+ ]
80
+ });
81
+ ` ` `
82
82
83
83
## configuration
84
84
@@ -91,17 +91,20 @@ By default, the configuration file is checked for changes every 60 seconds, and
91
91
92
92
To turn off configuration file change checking, configure with:
93
93
94
- var log4js = require('log4js');
95
- log4js.configure('my_log4js_configuration.json', {});
96
-
94
+ ` ` ` javascript
95
+ var log4js = require('log4js');
96
+ log4js.configure('my_log4js_configuration.json', {});
97
+ ` ` `
97
98
To specify a different period:
98
99
99
- log4js.configure('
880C
;file.json', { reloadSecs: 300 });
100
-
100
+ ` ` ` javascript
101
+ log4js.configure('file.json', { reloadSecs: 300 });
102
+ ` ` `
101
103
For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored.
102
104
103
- log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
104
-
105
+ ` ` ` javascript
106
+ log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
107
+ ` ` `
105
108
If you have already defined an absolute path for one of the FileAppenders in the configuration file, you could add a " absolute" : true to the particular FileAppender to override the cwd option passed . Here is an example configuration file:
106
109
107
110
#### my_log4js_configuration .json ####
0 commit comments