@@ -13,13 +13,27 @@ log4js.configure({
13
13
] ,
14
14
replaceConsole : true
15
15
} ) ;
16
- //log4js.addAppender(log4js.fileAppender('cheese.log'), 'cheese', 'console');
16
+
17
+ //to add an appender programmatically, and without clearing other appenders
18
+ //loadAppender is only necessary if you haven't already configured an appender of this type
19
+ log4js . loadAppender ( 'file' ) ;
20
+ log4js . addAppender ( log4js . appenders . file ( 'pants.log' ) , 'pants' ) ;
21
+ //a custom logger outside of the log4js/lib/appenders directory can be accessed like so
22
+ //log4js.loadAppender('what/you/would/put/in/require');
23
+ //log4js.addAppender(log4js.appenders['what/you/would/put/in/require'](args));
24
+ //or through configure as:
25
+ //log4js.configure({
26
+ // appenders: [ { type: 'what/you/would/put/in/require', otherArgs: 'blah' } ]
27
+ //});
17
28
18
29
var logger = log4js . getLogger ( 'cheese' ) ;
19
30
//only errors and above get logged.
31
+ //you can also set this log level in the config object
32
+ //via the levels field.
20
33
logger . setLevel ( 'ERROR' ) ;
21
34
22
- //console logging methds have been replaced with log4js ones.
35
+ //console logging methods have been replaced with log4js ones.
36
+ //so this will get coloured output on console, and appear in cheese.log
23
37
console . error ( "AAArgh! Something went wrong" , { some : "otherObject" , useful_for : "debug purposes" } ) ;
24
38
25
39
//these will not appear (logging level beneath error)
@@ -35,5 +49,10 @@ logger.fatal('Cheese was breeding ground for listeria.');
35
49
var anotherLogger = log4js . getLogger ( 'another' ) ;
36
50
anotherLogger . debug ( "Just checking" ) ;
37
51
52
+ //one for pants.log
53
+ //will also go to console, since that's configured for all categories
54
+ var pantsLog = log4js . getLogger ( 'pants' ) ;
55
+ pantsLog . debug ( "Something for pants" ) ;
56
+
38
57
39
58
0 commit comments