8000 Merge branch 'master' of github.com:csausdev/log4js-node · lalitkapoor/log4js-node@cf7d5f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf7d5f6

Browse files
author
csausdev
committed
Merge branch 'master' of github.com:csausdev/log4js-node
2 parents 7e79613 + 612d9ee commit cf7d5f6

19 files changed

+215
-2629
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a conversion of the [log4js](http://log4js.berlios.de/index.html)
44
framework to work with [node](http://nodejs.org). I've mainly stripped out the browser-specific code
5-
and tidied up some of the javascript. It includes a basic file logger, with log rolling based on file size.
5+
and tidied up some of the javascript. It includes a basic file logger, with log rolling based on file size. It also enhances the default console logging functions (console.log, console.debug, etc) so that they use log4js and can be directed to a file, with log rolling etc - which is handy if you have some third party modules that use console.log but want that output included in your application log files.
66

77
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).
88

@@ -12,14 +12,17 @@ npm install log4js
1212

1313
## tests
1414

15-
Tests now use [vows](http://vowsjs.org), run with `vows test/logging.js`. I am slowly porting the previous tests from jspec (run those with `node tests.js`), since jspec is no longer maintained.
15+
Tests now use [vows](http://vowsjs.org), run with `vows test/logging.js`.
1616

1717
## usage
1818

1919
Minimalist version:
2020
var log4js = require('log4js')();
2121
var logger = log4js.getLogger();
2222
logger.debug("Some debug messages");
23+
Even more minimalist version:
24+
require('log4js')();
25+
console.debug("Some debug messages");
2326
By default, log4js outputs to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see:
2427
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
2528

lib/log4js.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
* Website: http://log4js.berlios.de
4646
*/
4747
module.exports = function (fileSystem, standardOutput, configPaths) {
48-
var fs = fileSystem || require('fs'),
49-
standardOutput = standardOutput || console.log,
50-
configPaths = configPaths || require.paths,
51-
sys = require('sys'),
52-
events = require('events'),
48+
var events = require('events'),
5349
path = require('path'),
50+
sys = require('sys'),
51+
fs = fileSystem || require('fs'),
52+
standardOutput = standardOutput || sys.puts,
53+
configPaths = configPaths || require.paths,
5454
DEFAULT_CATEGORY = '[default]',
5555
ALL_CATEGORIES = '[all]',
5656
loggers = {},
@@ -279,9 +279,13 @@ module.exports = function (fileSystem, standardOutput, configPaths) {
279279
this.startTime = new Date();
280280
this.categoryName = categoryName;
281281
this.message = message;
282-
this.exception = exception;
283282
this.level = level;
284283
this.logger = logger;
284+
if (exception && exception.message && exception.name) {
285+
this.exception = exception;
286+
} else if (exception) {
287+
this.exception = new Error(sys.inspect(exception));
288+
}
285289
}
286290

287291
/**
@@ -614,8 +618,26 @@ module.exports = function (fileSystem, standardOutput, configPaths) {
614618

615619
};
616620

621+
function replaceConsole(logger) {
622+
function replaceWith (fn) {
623+
return function() {
624+
fn.apply(logger, arguments);
625+
}
626+
}
627+
628+
console.log = replaceWith(logger.info);
629+
console.debug = replaceWith(logger.debug);
630+
console.trace = replaceWith(logger.trace);
631+
console.info = replaceWith(logger.info);
632+
console.warn = replaceWith(logger.warn);
633+
console.error = replaceWith(logger.error);
634+
635+
}
636+
617637
//set ourselves up if we can find a default log4js.json
618638
configure(findConfiguration());
639+
//replace console.log, etc with log4js versions
640+
replaceConsole(getLogger("console"));
619641

620642
return {
621643
getLogger: getLogger,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "log4js",
3-
"version": "0.2.0",
3+
"version": "0.2.2",
44
"description": "Port of Log4js to work with node.",
55
"keywords": [
66
"logging",

spec/lib/images/bg.png

-154 Bytes
Binary file not shown.

spec/lib/images/hr.png

-321 Bytes
Binary file not shown.

spec/lib/images/loading.gif

-2.55 KB
Binary file not shown.

spec/lib/images/sprites.bg.png

-4.76 KB
Binary file not shown.

spec/lib/images/sprites.png

-3.54 KB
Binary file not shown.

spec/lib/images/vr.png

-145 Bytes
Binary file not shown.

spec/lib/jspec.css

Lines changed: 0 additions & 149 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0