Compare commits
26 Commits
date-rolli
...
release-0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67b19aeaf3 | ||
|
|
50eefcc701 | ||
|
|
8e53c6213e | ||
|
|
a15a628311 | ||
|
|
b75e3660f4 | ||
|
|
22da6226e5 | ||
|
|
a3bdac8e14 | ||
|
|
af428c5669 | ||
|
|
5c75ba9468 | ||
|
|
bec0d05847 | ||
|
|
e4bf405f20 | ||
|
|
95568f352b | ||
|
|
6da6f3c90e | ||
|
|
7f57d14e70 | ||
|
|
f478793da3 | ||
|
|
ec2f8fec3b | ||
|
|
0167c84ea5 | ||
|
|
3e1a27e522 | ||
|
|
8b42e46071 | ||
|
|
4a7a90ed53 | ||
|
|
a9307fd6da | ||
|
|
4739c65c68 | ||
|
|
892181f88f | ||
|
|
bdfa7f9a9b | ||
|
|
ad63b801f7 | ||
|
|
2bfad6362a |
143
README.md
143
README.md
@@ -21,10 +21,10 @@ NOTE: from log4js 0.5 onwards you'll need to explicitly enable replacement of no
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
{
|
{
|
||||||
appenders: [
|
appenders: [
|
||||||
{ type: "console" }
|
{ type: "console" }
|
||||||
],
|
],
|
||||||
replaceConsole: true
|
replaceConsole: true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -36,93 +36,98 @@ npm install log4js
|
|||||||
## usage
|
## usage
|
||||||
|
|
||||||
Minimalist version:
|
Minimalist version:
|
||||||
|
```javascript
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
var logger = log4js.getLogger();
|
var logger = log4js.getLogger();
|
||||||
logger.debug("Some debug messages");
|
logger.debug("Some debug messages");
|
||||||
|
```
|
||||||
By default, log4js outputs to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see:
|
By default, log4js outputs to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see:
|
||||||
|
```bash
|
||||||
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
|
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
|
||||||
|
```
|
||||||
See example.js for a full example, but here's a snippet (also in fromreadme.js):
|
See example.js for a full example, but here's a snippet (also in fromreadme.js):
|
||||||
|
```javascript
|
||||||
|
var log4js = require('log4js');
|
||||||
|
//console log is loaded by default, so you won't normally need to do this
|
||||||
|
//log4js.loadAppender('console');
|
||||||
|
log4js.loadAppender('file');
|
||||||
|
//log4js.addAppender(log4js.appenders.console());
|
||||||
|
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
|
||||||
|
|
||||||
var log4js = require('log4js');
|
var logger = log4js.getLogger('cheese');
|
||||||
//console log is loaded by default, so you won't normally need to do this
|
logger.setLevel('ERROR');
|
||||||
//log4js.loadAppender('console');
|
|
||||||
log4js.loadAppender('file');
|
|
||||||
//log4js.addAppender(log4js.appenders.console());
|
|
||||||
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
|
|
||||||
|
|
||||||
var logger = log4js.getLogger('cheese');
|
|
||||||
logger.setLevel('ERROR');
|
|
||||||
|
|
||||||
logger.trace('Entering cheese testing');
|
|
||||||
logger.debug('Got cheese.');
|
|
||||||
logger.info('Cheese is Gouda.');
|
|
||||||
logger.warn('Cheese is quite smelly.');
|
|
||||||
logger.error('Cheese is too ripe!');
|
|
||||||
logger.fatal('Cheese was breeding ground for listeria.');
|
|
||||||
|
|
||||||
|
logger.trace('Entering cheese testing');
|
||||||
|
logger.debug('Got cheese.');
|
||||||
|
logger.info('Cheese is Gouda.');
|
||||||
|
logger.warn('Cheese is quite smelly.');
|
||||||
|
logger.error('Cheese is too ripe!');
|
||||||
|
logger.fatal('Cheese was breeding ground for listeria.');
|
||||||
|
```
|
||||||
Output:
|
Output:
|
||||||
|
```bash
|
||||||
[2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
|
[2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
|
||||||
[2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.
|
[2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.
|
||||||
|
```
|
||||||
The first 5 lines of the code above could also be written as:
|
The first 5 lines of the code above could also be written as:
|
||||||
|
```javascript
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
log4js.configure({
|
log4js.configure({
|
||||||
appenders: [
|
appenders: [
|
||||||
{ type: 'console' },
|
{ type: 'console' },
|
||||||
{ type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
|
{ type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## configuration
|
## configuration
|
||||||
|
|
||||||
You can configure the appenders and log levels manually (as above), or provide a
|
You can configure the appenders and log levels manually (as above), or provide a
|
||||||
configuration file (`log4js.configure('path/to/file.json')`), or a configuration object.
|
configuration file (`log4js.configure('path/to/file.json')`), or a configuration object. The
|
||||||
|
configuration file location may also be specified via the environment variable
|
||||||
|
LOG4JS_CONFIG (`export LOG4JS_CONFIG=path/to/file.json`).
|
||||||
An example file can be found in `test/log4js.json`. An example config file with log rolling is in `test/with-log-rolling.json`.
|
An example file can be found in `test/log4js.json`. An example config file with log rolling is in `test/with-log-rolling.json`.
|
||||||
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.
|
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.
|
||||||
|
|
||||||
To turn off configuration file change checking, configure with:
|
To turn off configuration file change checking, configure with:
|
||||||
|
|
||||||
var log4js = require('log4js');
|
```javascript
|
||||||
log4js.configure('my_log4js_configuration.json', {});
|
var log4js = require('log4js');
|
||||||
|
log4js.configure('my_log4js_configuration.json', {});
|
||||||
|
```
|
||||||
To specify a different period:
|
To specify a different period:
|
||||||
|
|
||||||
log4js.configure('file.json', { reloadSecs: 300 });
|
```javascript
|
||||||
|
log4js.configure('file.json', { reloadSecs: 300 });
|
||||||
|
```
|
||||||
For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored.
|
For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored.
|
||||||
|
|
||||||
log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
|
```javascript
|
||||||
|
log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
|
||||||
|
```
|
||||||
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:
|
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:
|
||||||
|
```json
|
||||||
#### my_log4js_configuration.json ####
|
#### my_log4js_configuration.json ####
|
||||||
|
{
|
||||||
|
"appenders": [
|
||||||
{
|
{
|
||||||
"appenders": [
|
"type": "file",
|
||||||
{
|
"filename": "relative/path/to/log_file.log",
|
||||||
"type": "file",
|
"maxLogSize": 20480,
|
||||||
"filename": "relative/path/to/log_file.log",
|
"backups": 3,
|
||||||
"maxLogSize": 20480,
|
"category": "relative-logger"
|
||||||
"backups": 3,
|
},
|
||||||
"category": "relative-logger"
|
{
|
||||||
},
|
"type": "file",
|
||||||
{
|
"absolute": true,
|
||||||
"type": "file",
|
"filename": "/absolute/path/to/log_file.log",
|
||||||
"absolute": true,
|
"maxLogSize": 20480,
|
||||||
"filename": "/absolute/path/to/log_file.log",
|
"backups": 10,
|
||||||
"maxLogSize": 20480,
|
"category": "absolute-logger"
|
||||||
"backups": 10,
|
|
||||||
"category": "absolute-logger"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
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.
|
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.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|||||||
21
examples/patternLayout-tokens.js
Normal file
21
examples/patternLayout-tokens.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
var log4js = require('./lib/log4js');
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
"appenders": [
|
||||||
|
{
|
||||||
|
"type": "console",
|
||||||
|
"layout": {
|
||||||
|
"type": "pattern",
|
||||||
|
"pattern": "%[%r (%x{pid}) %p %c -%] %m%n",
|
||||||
|
"tokens": {
|
||||||
|
"pid" : function() { return process.pid; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
log4js.configure(config, {});
|
||||||
|
|
||||||
|
var logger = log4js.getLogger("app");
|
||||||
|
logger.info("Test log message");
|
||||||
@@ -16,20 +16,15 @@ function logServer(config) {
|
|||||||
function deserializeLoggingEvent(clientSocket, msg) {
|
function deserializeLoggingEvent(clientSocket, msg) {
|
||||||
var loggingEvent;
|
var loggingEvent;
|
||||||
try {
|
try {
|
||||||
loggingEvent = JSON.parse(msg);
|
loggingEvent = JSON.parse(msg);
|
||||||
loggingEvent.startTime = new Date(loggingEvent.startTime);
|
loggingEvent.startTime = new Date(loggingEvent.startTime);
|
||||||
loggingEvent.level.toString = function levelToString() {
|
loggingEvent.level = log4js.levels.toLevel(loggingEvent.level.levelStr);
|
||||||
return loggingEvent.level.levelStr;
|
|
||||||
};
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// JSON.parse failed, just log the contents probably a naughty.
|
// JSON.parse failed, just log the contents probably a naughty.
|
||||||
loggingEvent = {
|
loggingEvent = {
|
||||||
startTime: new Date(),
|
startTime: new Date(),
|
||||||
categoryName: 'log4js',
|
categoryName: 'log4js',
|
||||||
level: { toString: function () {
|
level: log4js.levels.ERROR,
|
||||||
return 'ERROR';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data: [ 'Unable to parse log:', msg ]
|
data: [ 'Unable to parse log:', msg ]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -120,11 +115,11 @@ function createAppender(config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure(config) {
|
function configure(config, options) {
|
||||||
var actualAppender;
|
var actualAppender;
|
||||||
if (config.appender && config.mode === 'master') {
|
if (config.appender && config.mode === 'master') {
|
||||||
log4js.loadAppender(config.appender.type);
|
log4js.loadAppender(config.appender.type);
|
||||||
actualAppender = log4js.appenderMakers[config.appender.type](config.appender);
|
actualAppender = log4js.appenderMakers[config.appender.type](config.appender, options);
|
||||||
config.actualAppender = actualAppender;
|
config.actualAppender = actualAppender;
|
||||||
}
|
}
|
||||||
return createAppender(config);
|
return createAppender(config);
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ var dateFormat = require('./date_format')
|
|||||||
, "coloured": function() { return colouredLayout; }
|
, "coloured": function() { return colouredLayout; }
|
||||||
, "pattern": function (config) {
|
, "pattern": function (config) {
|
||||||
var pattern = config.pattern || undefined;
|
var pattern = config.pattern || undefined;
|
||||||
return patternLayout(pattern);
|
var tokens = config.tokens || undefined;
|
||||||
}
|
return patternLayout(pattern, tokens);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
, colours = {
|
, colours = {
|
||||||
ALL: "grey"
|
ALL: "grey"
|
||||||
@@ -24,7 +25,6 @@ var dateFormat = require('./date_format')
|
|||||||
, OFF: "grey"
|
, OFF: "grey"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function formatLogData(logData) {
|
function formatLogData(logData) {
|
||||||
var output = ""
|
var output = ""
|
||||||
, data = Array.isArray(logData) ? logData.slice() : Array.prototype.slice.call(arguments)
|
, data = Array.isArray(logData) ? logData.slice() : Array.prototype.slice.call(arguments)
|
||||||
@@ -58,30 +58,36 @@ function formatLogData(logData) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var styles = {
|
||||||
|
//styles
|
||||||
|
'bold' : [1, 22],
|
||||||
|
'italic' : [3, 23],
|
||||||
|
'underline' : [4, 24],
|
||||||
|
'inverse' : [7, 27],
|
||||||
|
//grayscale
|
||||||
|
'white' : [37, 39],
|
||||||
|
'grey' : [90, 39],
|
||||||
|
'black' : [90, 39],
|
||||||
|
//colors
|
||||||
|
'blue' : [34, 39],
|
||||||
|
'cyan' : [36, 39],
|
||||||
|
'green' : [32, 39],
|
||||||
|
'magenta' : [35, 39],
|
||||||
|
'red' : [31, 39],
|
||||||
|
'yellow' : [33, 39]
|
||||||
|
};
|
||||||
|
|
||||||
|
function colorizeStart(style) {
|
||||||
|
return style ? '\033[' + styles[style][0] + 'm' : '';
|
||||||
|
}
|
||||||
|
function colorizeEnd(style) {
|
||||||
|
return style ? '\033[' + styles[style][1] + 'm' : '';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Taken from masylum's fork (https://github.com/masylum/log4js-node)
|
* Taken from masylum's fork (https://github.com/masylum/log4js-node)
|
||||||
*/
|
*/
|
||||||
function colorize (str, style) {
|
function colorize (str, style) {
|
||||||
var styles = {
|
return colorizeStart(style) + str + colorizeEnd(style);
|
||||||
//styles
|
|
||||||
'bold' : [1, 22],
|
|
||||||
'italic' : [3, 23],
|
|
||||||
'underline' : [4, 24],
|
|
||||||
'inverse' : [7, 27],
|
|
||||||
//grayscale
|
|
||||||
'white' : [37, 39],
|
|
||||||
'grey' : [90, 39],
|
|
||||||
'black' : [90, 39],
|
|
||||||
//colors
|
|
||||||
'blue' : [34, 39],
|
|
||||||
'cyan' : [36, 39],
|
|
||||||
'green' : [32, 39],
|
|
||||||
'magenta' : [35, 39],
|
|
||||||
'red' : [31, 39],
|
|
||||||
'yellow' : [33, 39]
|
|
||||||
};
|
|
||||||
return style ? '\033[' + styles[style][0] + 'm' + str +
|
|
||||||
'\033[' + styles[style][1] + 'm' : str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function timestampLevelAndCategory(loggingEvent, colour) {
|
function timestampLevelAndCategory(loggingEvent, colour) {
|
||||||
@@ -134,12 +140,26 @@ function messagePassThroughLayout (loggingEvent) {
|
|||||||
* - %d date in various formats
|
* - %d date in various formats
|
||||||
* - %% %
|
* - %% %
|
||||||
* - %n newline
|
* - %n newline
|
||||||
* Takes a pattern string and returns a layout function.
|
* - %x{<tokenname>} add dynamic tokens to your log. Tokens are specified in the tokens parameter
|
||||||
|
* You can use %[ and %] to define a colored block.
|
||||||
|
*
|
||||||
|
* Tokens are specified as simple key:value objects.
|
||||||
|
* The key represents the token name whereas the value can be a string or function
|
||||||
|
* which is called to extract the value to put in the log message. If token is not
|
||||||
|
* found, it doesn't replace the field.
|
||||||
|
*
|
||||||
|
* A sample token would be: { "pid" : function() { return process.pid; } }
|
||||||
|
*
|
||||||
|
* Takes a pattern string, array of tokens and returns a layout function.
|
||||||
|
* @param {String} Log format pattern String
|
||||||
|
* @param {object} map object of different tokens
|
||||||
|
* @return {Function}
|
||||||
* @author Stephan Strittmatter
|
* @author Stephan Strittmatter
|
||||||
|
* @author Jan Schmidle
|
||||||
*/
|
*/
|
||||||
function patternLayout (pattern) {
|
function patternLayout (pattern, tokens) {
|
||||||
var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
|
var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
|
||||||
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([cdmnpr%])(\{([^\}]+)\})?|([^%]+)/;
|
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdmnprx%])(\{([^\}]+)\})?|([^%]+)/;
|
||||||
|
|
||||||
pattern = pattern || TTCC_CONVERSION_PATTERN;
|
pattern = pattern || TTCC_CONVERSION_PATTERN;
|
||||||
|
|
||||||
@@ -206,9 +226,26 @@ function patternLayout (pattern) {
|
|||||||
case "r":
|
case "r":
|
||||||
replacement = "" + loggingEvent.startTime.toLocaleTimeString();
|
replacement = "" + loggingEvent.startTime.toLocaleTimeString();
|
||||||
break;
|
break;
|
||||||
|
case "[":
|
||||||
|
replacement = colorizeStart(colours[loggingEvent.level.toString()]);
|
||||||
|
break;
|
||||||
|
case "]":
|
||||||
|
replacement = colorizeEnd(colours[loggingEvent.level.toString()]);
|
||||||
|
break;
|
||||||
case "%":
|
case "%":
|
||||||
replacement = "%";
|
replacement = "%";
|
||||||
break;
|
break;
|
||||||
|
case "x":
|
||||||
|
if(typeof(tokens[specifier]) !== 'undefined') {
|
||||||
|
if(typeof(tokens[specifier]) === 'function') {
|
||||||
|
replacement = tokens[specifier]();
|
||||||
|
} else {
|
||||||
|
replacement = tokens[specifier];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replacement = matchedString;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
replacement = matchedString;
|
replacement = matchedString;
|
||||||
break;
|
break;
|
||||||
@@ -248,7 +285,6 @@ function patternLayout (pattern) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
basicLayout: basicLayout
|
basicLayout: basicLayout
|
||||||
, messagePassThroughLayout: messagePassThroughLayout
|
, messagePassThroughLayout: messagePassThroughLayout
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ function initReloadConfiguration(filename, options) {
|
|||||||
|
|
||||||
function configure(configurationFileOrObject, options) {
|
function configure(configurationFileOrObject, options) {
|
||||||
var config = configurationFileOrObject;
|
var config = configurationFileOrObject;
|
||||||
|
config = config || process.env.LOG4JS_CONFIG;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if (config === undefined || config === null || typeof(config) === 'string') {
|
if (config === undefined || config === null || typeof(config) === 'string') {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
var events = require('events'),
|
var events = require('events'),
|
||||||
|
Dequeue = require('dequeue'),
|
||||||
util = require('util');
|
util = require('util');
|
||||||
|
|
||||||
module.exports = BufferedWriteStream;
|
module.exports = BufferedWriteStream;
|
||||||
@@ -6,7 +7,7 @@ module.exports = BufferedWriteStream;
|
|||||||
function BufferedWriteStream(stream) {
|
function BufferedWriteStream(stream) {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.buffer = [];
|
this.buffer = new Dequeue();
|
||||||
this.canWrite = false;
|
this.canWrite = false;
|
||||||
this.bytes = 0;
|
this.bytes = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "log4js",
|
"name": "log4js",
|
||||||
"version": "0.5.2",
|
"version": "0.5.8",
|
||||||
"description": "Port of Log4js to work with node.",
|
"description": "Port of Log4js to work with node.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"logging",
|
"logging",
|
||||||
@@ -17,7 +17,9 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "http://github.com/nomiddlename/log4js-node/issues"
|
"url": "http://github.com/nomiddlename/log4js-node/issues"
|
||||||
},
|
},
|
||||||
"engines": [ "node >=0.6" ],
|
"engines": {
|
||||||
|
"node": "~0.6||~0.8"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vows"
|
"test": "vows"
|
||||||
},
|
},
|
||||||
@@ -26,7 +28,8 @@
|
|||||||
"lib": "lib"
|
"lib": "lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "0.1.15"
|
"async": "0.1.15",
|
||||||
|
"dequeue": "1.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vows": "0.6.2",
|
"vows": "0.6.2",
|
||||||
|
|||||||
@@ -84,6 +84,48 @@ vows.describe('log4js configure').addBatch({
|
|||||||
'should add appender configure function to appenderMakers': function(log4js) {
|
'should add appender configure function to appenderMakers': function(log4js) {
|
||||||
assert.isFunction(log4js.appenderMakers['some/other/external']);
|
assert.isFunction(log4js.appenderMakers['some/other/external']);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'when configuration file loaded via LOG4JS_CONFIG environment variable': {
|
||||||
|
topic: function() {
|
||||||
|
process.env.LOG4JS_CONFIG = 'some/path/to/mylog4js.json';
|
||||||
|
var fileRead = 0,
|
||||||
|
modulePath = 'some/path/to/mylog4js.json',
|
||||||
|
pathsChecked = [],
|
||||||
|
mtime = new Date(),
|
||||||
|
fakeFS = {
|
||||||
|
config: { appenders: [ { type: 'console', layout: { type: 'messagePassThrough' } } ],
|
||||||
|
levels: { 'a-test' : 'INFO' } },
|
||||||
|
readdirSync: function(dir) {
|
||||||
|
return require('fs').readdirSync(dir);
|
||||||
|
},
|
||||||
|
readFileSync: function (file, encoding) {
|
||||||
|
fileRead += 1;
|
||||||
|
assert.isString(file);
|
||||||
|
assert.equal(file, modulePath);
|
||||||
|
assert.equal(encoding, 'utf8');
|
||||||
|
return JSON.stringify(fakeFS.config);
|
||||||
|
},
|
||||||
|
statSync: function (path) {
|
||||||
|
pathsChecked.push(path);
|
||||||
|
if (path === modulePath) {
|
||||||
|
return { mtime: mtime };
|
||||||
|
} else {
|
||||||
|
throw new Error("no such file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
log4js = sandbox.require('../lib/log4js',
|
||||||
|
{
|
||||||
|
requires: {
|
||||||
|
'fs': fakeFS,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
delete process.env.LOG4JS_CONFIG;
|
||||||
|
return fileRead;
|
||||||
|
},
|
||||||
|
'should load the specified local configuration file' : function(fileRead) {
|
||||||
|
assert.equal(fileRead, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).exportTo(module);
|
}).exportTo(module);
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ assert = require('assert');
|
|||||||
//used for patternLayout tests.
|
//used for patternLayout tests.
|
||||||
function test(args, pattern, value) {
|
function test(args, pattern, value) {
|
||||||
var layout = args[0]
|
var layout = args[0]
|
||||||
, event = args[1];
|
, event = args[1]
|
||||||
|
, tokens = args[2];
|
||||||
|
|
||||||
assert.equal(layout(pattern)(event), value);
|
assert.equal(layout(pattern, tokens)(event), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('log4js layouts').addBatch({
|
vows.describe('log4js layouts').addBatch({
|
||||||
@@ -175,8 +176,12 @@ vows.describe('log4js layouts').addBatch({
|
|||||||
level: {
|
level: {
|
||||||
toString: function() { return "DEBUG"; }
|
toString: function() { return "DEBUG"; }
|
||||||
}
|
}
|
||||||
}, layout = require('../lib/layouts').patternLayout;
|
}, layout = require('../lib/layouts').patternLayout
|
||||||
return [layout, event];
|
, tokens = {
|
||||||
|
testString: 'testStringToken',
|
||||||
|
testFunction: function() { return 'testFunctionToken'; }
|
||||||
|
};
|
||||||
|
return [layout, event, tokens];
|
||||||
},
|
},
|
||||||
|
|
||||||
'should default to "time logLevel loggerName - message"': function(args) {
|
'should default to "time logLevel loggerName - message"': function(args) {
|
||||||
@@ -243,9 +248,21 @@ vows.describe('log4js layouts').addBatch({
|
|||||||
test(args, '%-6p', 'DEBUG ');
|
test(args, '%-6p', 'DEBUG ');
|
||||||
test(args, '%-8p', 'DEBUG ');
|
test(args, '%-8p', 'DEBUG ');
|
||||||
test(args, '%-10p', 'DEBUG ');
|
test(args, '%-10p', 'DEBUG ');
|
||||||
}
|
},
|
||||||
|
'%[%r%] should output colored time': function(args) {
|
||||||
|
test(args, '%[%r%]', '\033[36m14:18:30\033[39m');
|
||||||
|
},
|
||||||
|
'%x{testString} should output the string stored in tokens': function(args) {
|
||||||
|
test(args, '%x{testString}', 'testStringToken');
|
||||||
|
},
|
||||||
|
'%x{testFunction} should output the result of the function stored in tokens': function(args) {
|
||||||
|
test(args, '%x{testFunction}', 'testFunctionToken');
|
||||||
|
},
|
||||||
|
'%x{doesNotExist} should output the string stored in tokens': function(args) {
|
||||||
|
test(args, '%x{doesNotExist}', '%x{doesNotExist}');
|
||||||
|
},
|
||||||
|
'%x should output the string stored in tokens': function(args) {
|
||||||
|
test(args, '%x', '%x');
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
|
||||||
|
|||||||
@@ -181,14 +181,14 @@ vows.describe('Multiprocess Appender').addBatch({
|
|||||||
},
|
},
|
||||||
'when a client connects': {
|
'when a client connects': {
|
||||||
topic: function(net) {
|
topic: function(net) {
|
||||||
var logString = JSON.stringify({ level: 'DEBUG', data: ['some debug']}) + '__LOG4JS__';
|
var logString = JSON.stringify({ level: { level: 10000, levelStr: 'DEBUG' }, data: ['some debug']}) + '__LOG4JS__';
|
||||||
|
|
||||||
net.cbs['connect']();
|
net.cbs['connect']();
|
||||||
net.cbs['data'](JSON.stringify({ level: 'ERROR', data: ['an error message'] }) + '__LOG4JS__');
|
net.cbs['data'](JSON.stringify({ level: { level: 40000, levelStr: 'ERROR' }, data: ['an error message'] }) + '__LOG4JS__');
|
||||||
net.cbs['data'](logString.substring(0, 10));
|
net.cbs['data'](logString.substring(0, 10));
|
||||||
net.cbs['data'](logString.substring(10));
|
net.cbs['data'](logString.substring(10));
|
||||||
net.cbs['data'](logString + logString + logString);
|
net.cbs['data'](logString + logString + logString);
|
||||||
net.cbs['end'](JSON.stringify({ level: 'FATAL', data: ["that's all folks"] }) + '__LOG4JS__');
|
net.cbs['end'](JSON.stringify({ level: { level: 50000, levelStr: 'FATAL' }, data: ["that's all folks"] }) + '__LOG4JS__');
|
||||||
net.cbs['data']('bad message__LOG4JS__');
|
net.cbs['data']('bad message__LOG4JS__');
|
||||||
return net;
|
return net;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user