Added log rolling to config files
This commit is contained in:
parent
75b9e82cac
commit
966b8ced4f
@ -2,7 +2,7 @@
|
||||
|
||||
This is a conversion of the [log4js](http://log4js.berlios.de/index.html)
|
||||
framework to work with [node](http://nodejs.org). I've mainly stripped out the browser-specific code
|
||||
and tidied up some of the javascript.
|
||||
and tidied up some of the javascript. It includes a basic file logger, with log rolling based on file size.
|
||||
|
||||
NOTE: since v0.2.0 require('log4js') returns a function, so you need to call that function in your code before you can use it. I've done this to make testing easier (allows dependency injection).
|
||||
|
||||
@ -47,13 +47,11 @@ Output
|
||||
## configuration
|
||||
|
||||
You can either configure the appenders and log levels manually (as above), or provide a
|
||||
configuration file (`log4js.configure('path/to/file.json')`) explicitly, or just let log4js look for a file called `log4js.json` (it looks in the current directory first, then the require paths, and finally looks for the default config included in the same directory as the log4js.js file).
|
||||
An example file can be found in test/log4js.json
|
||||
configuration file (`log4js.configure('path/to/file.json')`) explicitly, or just let log4js look for a file called `log4js.json` (it looks in the current directory first, then the require paths, and finally looks for the default config included in the same directory as the `log4js.js` file).
|
||||
An example file can be found in `test/log4js.json`. An example config file with log rolling is in `test/with-log-rolling.json`
|
||||
|
||||
## todo
|
||||
|
||||
I need to make a RollingFileAppender, which will do log rotation.
|
||||
|
||||
patternLayout has no tests. This is mainly because I haven't found a use for it yet,
|
||||
and am not entirely sure what it was supposed to do. It is more-or-less intact from
|
||||
the original log4js.
|
||||
|
@ -71,7 +71,7 @@ module.exports = function (fileSystem, standardOutput, configPaths) {
|
||||
if (config.layout) {
|
||||
layout = layoutMakers[config.layout.type](config.layout);
|
||||
}
|
||||
return fileAppender(config.filename, layout);
|
||||
return fileAppender(config.filename, layout, config.maxLogSize, config.backups, config.pollInterval);
|
||||
},
|
||||
"console": function(config) {
|
||||
var layout;
|
||||
|
@ -186,6 +186,9 @@ vows.describe('log4js').addBatch({
|
||||
},
|
||||
readFileSync: function(file, encoding) {
|
||||
return require('fs').readFileSync(file, encoding);
|
||||
},
|
||||
watchFile: function(file) {
|
||||
messages.watchedFile = file;
|
||||
}
|
||||
},
|
||||
log4js = require('../lib/log4js')(fakeFS);
|
||||
@ -220,6 +223,12 @@ vows.describe('log4js').addBatch({
|
||||
assert.length(messages['tmp-tests-warnings.log'], 2);
|
||||
assert.deepEqual(messages['tmp-tests.log'], ['main\n','both\n','both\n','main\n']);
|
||||
assert.deepEqual(messages['tmp-tests-warnings.log'], ['both\n','both\n']);
|
||||
},
|
||||
'should handle fileAppender with log rolling' : function(args) {
|
||||
var log4js = args[0], messages = args[1];
|
||||
delete messages['tmp-test.log'];
|
||||
log4js.configure('test/with-log-rolling.json');
|
||||
assert.equal(messages.watchedFile, 'tmp-test.log');
|
||||
}
|
||||
},
|
||||
|
||||
|
11
test/with-log-rolling.json
Normal file
11
test/with-log-rolling.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"appenders": [
|
||||
{
|
||||
"type": "file",
|
||||
"filename": "tmp-test.log",
|
||||
"maxLogSize": 1024,
|
||||
"backups": 3,
|
||||
"pollInterval": 15
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user