Skip to content

Commit 9840b75

Browse files
committed
Log() accepts string as log level
1 parent d4ce7a8 commit 9840b75

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Specifying a specific stream:
2424
, Log = require('log')
2525
, log = new Log(Log.DEBUG, fs.createWriteStream('my.log'));
2626

27+
Instead of the log level constants, you may also supply a string:
28+
29+
var Log = require('log')
30+
, log = new Log('warning');
31+
2732
## Log Levels
2833

2934
Mirror that of syslog:

example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
var Log = require('./lib/log')
7-
, log = new Log(Log.INFO);
7+
, log = new Log('notice');
88

99
log.debug('a debug message');
1010
log.info('a info message');

lib/log.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
var Log = exports = module.exports = function Log(level, stream){
18+
if ('string' == typeof level) level = exports[level.toUpperCase()];
1819
this.level = level || exports.DEBUG;
1920
this.stream = stream || process.stdout;
2021
};

0 commit comments

Comments
 (0)