Skip to content
Newer
Older
100644 139 lines (100 sloc) 4.97 KB
d276bbc @nomiddlename Bumped version number, added travis status to readme
authored
1 # log4js-node [![Build Status](https://secure.travis-ci.org/nomiddlename/log4js-node.png?branch=master)](http://travis-ci.org/nomiddlename/log4js-node)
a95c015 @nomiddlename First commit.
authored
2
12e71bd @nomiddlename fixed to work with node 0.5.x
authored
3
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
4 This is a conversion of the [log4js](http://log4js.berlios.de/index.html)
bef2075 @nomiddlename moved some docs to the wiki
authored
5 framework to work with [node](http://nodejs.org). I've mainly stripped out the browser-specific code and tidied up some of the javascript.
6
7 Out of the box it supports the following features:
8
9 * coloured console logging
10 * replacement of node's console.log functions (optional)
11 * file appender, with log rolling based on file size
12 * SMTP appender
13 * GELF appender
14 * hook.io appender
15 * multiprocess appender (useful when you've got worker processes)
16 * a logger for connect/express servers
17 * configurable log message layout/patterns
18 * different log levels for different log categories (make some parts of your app log as DEBUG, others only ERRORS, etc.)
f386f00 @nomiddlename removed the console.log replacement from the readme
authored
19
6f0dfa0 @nomiddlename Added note about console.log replacement.
authored
20 NOTE: from log4js 0.5 onwards you'll need to explicitly enable replacement of node's console.log functions. Do this either by calling `log4js.replaceConsole()` or configuring with an object or json file like this:
21
22 ```javascript
23 {
24 appenders: [
25 { type: "console" }
26 ],
27 replaceConsole: true
28 }
29 ```
f386f00 @nomiddlename removed the console.log replacement from the readme
authored
30
2fe9b0b @nomiddlename added npm instructions to readme
authored
31 ## installation
32
33 npm install log4js
34
a95c015 @nomiddlename First commit.
authored
35
36 ## usage
37
6032c07 @nomiddlename Added loading of config from require paths, and now defaults to conso…
authored
38 Minimalist version:
ffdfca7 @nomiddlename fixing some formatting problems
authored
39
d7ffa59 @nomiddlename moved level colours into layouts where they belong, updated README
authored
40 var log4js = require('log4js');
6032c07 @nomiddlename Added loading of config from require paths, and now defaults to conso…
authored
41 var logger = log4js.getLogger();
42 logger.debug("Some debug messages");
ffdfca7 @nomiddlename fixing some formatting problems
authored
43
4406f21 @nomiddlename added test for log roller, not written yet
authored
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:
ffdfca7 @nomiddlename fixing some formatting problems
authored
45
6032c07 @nomiddlename Added loading of config from require paths, and now defaults to conso…
authored
46 [2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
47
1aed671 @nomiddlename added fromreadme.js example, updated README
authored
48 See example.js for a full example, but here's a snippet (also in fromreadme.js):
a95c015 @nomiddlename First commit.
authored
49
bef2075 @nomiddlename moved some docs to the wiki
authored
50 var log4js = require('log4js');
1aed671 @nomiddlename added fromreadme.js example, updated README
authored
51 //console log is loaded by default, so you won't normally need to do this
52 //log4js.loadAppender('console');
bef2075 @nomiddlename moved some docs to the wiki
authored
53 log4js.loadAppender('file');
1aed671 @nomiddlename added fromreadme.js example, updated README
authored
54 //log4js.addAppender(log4js.appenders.console());
bef2075 @nomiddlename moved some docs to the wiki
authored
55 log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
56
5faad92 @nomiddlename tidying up the readme
authored
57 var logger = log4js.getLogger('cheese');
58 logger.setLevel('ERROR');
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
59
5faad92 @nomiddlename tidying up the readme
authored
60 logger.trace('Entering cheese testing');
61 logger.debug('Got cheese.');
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
62 logger.info('Cheese is Gouda.');
5faad92 @nomiddlename tidying up the readme
authored
63 logger.warn('Cheese is quite smelly.');
64 logger.error('Cheese is too ripe!');
65 logger.fatal('Cheese was breeding ground for listeria.');
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
66
ffdfca7 @nomiddlename fixing some formatting problems
authored
67 Output:
68
30121af @nomiddlename removing superfluous escaping of readme log output
authored
69 [2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
70 [2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.
bef2075 @nomiddlename moved some docs to the wiki
authored
71
72 The first 5 lines of the code above could also be written as:
a95c015 @nomiddlename First commit.
authored
73
bef2075 @nomiddlename moved some docs to the wiki
authored
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
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
82
a95c015 @nomiddlename First commit.
authored
83 ## configuration
84
bef2075 @nomiddlename moved some docs to the wiki
authored
85 You can configure the appenders and log levels manually (as above), or provide a
86 configuration file (`log4js.configure('path/to/file.json')`), or a configuration object.
69e6493 @danbell Added functionality to reload configuration file periodically.
danbell authored
87 An example file can be found in `test/log4js.json`. An example config file with log rolling is in `test/with-log-rolling.json`.
bef2075 @nomiddlename moved some docs to the wiki
authored
88 By default, the configuration file is checked for changes every 60 seconds, and if changed, reloaded. This allows changes to logging levels to occur without restarting the application.
69e6493 @danbell Added functionality to reload configuration file periodically.
danbell authored
89
e6b69ff @danbell Added more documentation on new functionality.
danbell authored
90 To turn off configuration file change checking, configure with:
91
3b24109 @danbell Fixed indentation on markdown file.
danbell authored
92 var log4js = require('log4js');
93 log4js.configure('my_log4js_configuration.json', {});
e6b69ff @danbell Added more documentation on new functionality.
danbell authored
94
95 To specify a different period:
96
bef2075 @nomiddlename moved some docs to the wiki
authored
97 log4js.configure('file.json', { reloadSecs: 300 });
a95c015 @nomiddlename First commit.
authored
98
0c04c68 @shripadk More fixes + Test for "cwd" option
shripadk authored
99 For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored.
100
101 log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
102
103 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:
104
105 #### my_log4js_configuration.json ####
106 {
107 "appenders": [
108 {
109 "type": "file",
110 "filename": "relative/path/to/log_file.log",
111 "maxLogSize": 20480,
112 "backups": 3,
113 "category": "relative-logger"
114 },
115 {
116 "type": "file",
117 "absolute": true,
118 "filename": "/absolute/path/to/log_file.log",
119 "maxLogSize": 20480,
120 "backups": 10,
121 "category": "absolute-logger"
122 }
123 ]
124 }
bef2075 @nomiddlename moved some docs to the wiki
authored
125
82a6bee @nomiddlename Fixed the wiki links.
authored
126 Documentation for most of the core appenders can be found on the [wiki](log4js-node/wiki/Appenders), otherwise take a look at the tests and the examples.
0c04c68 @shripadk More fixes + Test for "cwd" option
shripadk authored
127
bef2075 @nomiddlename moved some docs to the wiki
authored
128 ## Documentation
82a6bee @nomiddlename Fixed the wiki links.
authored
129 See the [wiki](log4js-node/wiki). Improve the [wiki](log4js-node/wiki), please.
a95c015 @nomiddlename First commit.
authored
130
bef2075 @nomiddlename moved some docs to the wiki
authored
131 ## Contributing
82a6bee @nomiddlename Fixed the wiki links.
authored
132 Contributions welcome, but take a look at the [rules](log4js-node/wiki/Contributing) first.
a95c015 @nomiddlename First commit.
authored
133
134 ## License
135
136 The original log4js was distributed under the Apache 2.0 License, and so is this. I've tried to
f82ecf8 Update readme to describe hook.io usage
Danny Brain authored
137 keep the original copyright and author credits in place, except in sections that I have rewritten
a95c015 @nomiddlename First commit.
authored
138 extensively.
Something went wrong with that request. Please try again.