Skip to content

Commit 1a36097

Browse files
committed
[doc minor] Added more code documentation. Small updates to some var names and to README.md
1 parent b1178c6 commit 1a36097

File tree

10 files changed

+87
-18
lines changed

10 files changed

+87
-18
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2009 Charlie Robbins
1+
Copyright (c) 2010 Charlie Robbins
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ There also seemed to be a log of libraries out there that were coupling their im
3636
2. [socket.io](http://socket.io)
3737
3. [node-rlog](https://github.com/jbrisbin/node-rlog)
3838

39+
## Road Map
40+
1. Make levels configurable for user preference (npm-style, syslog-style, etc)
41+
2. Create API for reading from logs across all transports.
42+
3. Add more transports and make existing transports more robust:
43+
a. Riak
44+
b. CouchDB
45+
c. Redis
3946

4047
## Run Tests
4148
All of the winston tests are written in [vows][1], and cover all of the use cases described above. You will need to add valid credentials for the various transports included to test/test-config.json before running tests:

lib/winston.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
require.paths.unshift(require('path').join(__dirname));
1010

1111
var winston = exports;
12+
13+
//
14+
// Include transports defined by default by winston
15+
//
1216
winston.transports = require('winston/transports');
1317

1418
//
@@ -45,6 +49,10 @@ Object.keys(defaultLogger.levels).forEach(function (level) {
4549
};
4650
});
4751

52+
//
53+
// function defaultTransports ()
54+
// returns the transports set on the default winston logger
55+
//
4856
winston.defaultTransports = function () {
4957
return defaultLogger.transports;
5058
};

lib/winston/logger.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
1+
/*
2+
* logger.js: Core logger object used by winston.
3+
*
4+
* (C) 2010 Charlie Robbins
5+
* MIT LICENCE
6+
*
7+
*/
8+
29
require.paths.unshift(require('path').join(__dirname, '..'));
310

411
var util = require('util'),
@@ -40,6 +47,7 @@ var Logger = exports.Logger = function (options) {
4047

4148
util.inherits(Logger, events.EventEmitter);
4249

50+
// TODO: Make levels configurable
4351
var levels = Logger.prototype.levels = {
4452
silly: 0,
4553
verbose: 1,
@@ -51,7 +59,7 @@ var levels = Logger.prototype.levels = {
5159

5260
//
5361
// Define prototype methods for each log level
54-
// i.e. logger.log('info', msg) <=> logger.info(msg)
62+
// e.g. logger.log('info', msg) <=> logger.info(msg)
5563
//
5664
Object.keys(levels).forEach(function (level) {
5765
Logger.prototype[level] = function (msg, meta, callback) {
@@ -100,6 +108,10 @@ Logger.prototype.log = function (level, msg) {
100108
};
101109
};
102110

111+
//
112+
// function add (transport, [options])
113+
// Adds a transport of the specified type to this instance.
114+
//
103115
Logger.prototype.add = function (transport, options) {
104116
var name = winston.findTransport(transport);
105117

@@ -110,6 +122,10 @@ Logger.prototype.add = function (transport, options) {
110122
return this;
111123
};
112124

125+
//
126+
// function remove (transport)
127+
// Removes a transport of the specified type from this instance.
128+
//
113129
Logger.prototype.remove = function (transport) {
114130
var name = winston.findTransport(transport);
115131
if (!this.transports[name]) throw new Error('Transport ' + name + ' not attached to this instance');
@@ -120,15 +136,21 @@ Logger.prototype.remove = function (transport) {
120136
return this;
121137
};
122138

139+
//
140+
// function profile (msg, [callback])
141+
// Tracks the time inbetween subsequent calls to this method
142+
// with the same [msg] parameter. The second call to this method
143+
// will log the difference in milliseconds along with the message.
144+
//
123145
Logger.prototype.profile = function (name, callback) {
124146
var now = Date.now(), then;
125147

126-
if (this.profilers[name]) {
127-
then = this.profilers[name];
128-
delete this.profilers[name];
129-
return this.info(now - then + 'ms - ' + name, callback);
148+
if (this.profilers[msg]) {
149+
then = this.profilers[msg];
150+
delete this.profilers[msg];
151+
return this.info(now - then + 'ms - ' + msg, callback);
130152
}
131153
else {
132-
this.profilers[name] = now;
154+
this.profilers[msg] = now;
133155
}
134156
};

lib/winston/transports/console.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ var util = require('util'),
1010
colors = require('colors'),
1111
log = require('./../utils').log;
1212

13+
//
14+
// function Console (options)
15+
// Constructor for the Console transport object.
16+
//
1317
var Console = exports.Console = function (options) {
1418
options = options || {};
1519

@@ -19,6 +23,10 @@ var Console = exports.Console = function (options) {
1923
this.colorize = options.colorize;
2024
};
2125

26+
//
27+
// function log (level, msg, [meta], callback)
28+
// Core logging method exposed to Winston. Metadata is optional.
29+
//
2230
Console.prototype.log = function (level, msg, meta, callback) {
2331
if (!this.silent) {
2432
var output = log(level, msg, meta);

lib/winston/transports/file.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ var util = require('util'),
1111
colors = require('colors'),
1212
log = require('./../utils').log;
1313

14+
//
15+
// function File (options)
16+
// Constructor for the File transport object.
17+
//
1418
var File = exports.File = function (options) {
1519
options = options || {}
1620

@@ -24,6 +28,10 @@ var File = exports.File = function (options) {
2428
this.colorize = options.colorize;
2529
};
2630

31+
//
32+
// function log (level, msg, [meta], callback)
33+
// Core logging method exposed to Winston. Metadata is optional.
34+
//
2735
File.prototype.log = function (level, msg, meta, callback) {
2836
if (!this.silent) {
2937
var output = log(level, msg, meta) + '\n';

lib/winston/transports/loggly.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
var loggly = require('loggly'),
1010
utils = require('./../utils');
1111

12+
//
13+
// function Loggly (options)
14+
// Constructor for the Loggly transport object.
15+
//
1216
var Loggly = exports.Loggly = function (options) {
1317
options = options || {};
1418
if (!options.auth) throw new Error('Loggly authentication is required');
@@ -39,6 +43,10 @@ var Loggly = exports.Loggly = function (options) {
3943
}
4044
};
4145

46+
//
47+
// function log (level, msg, [meta], callback)
48+
// Core logging method exposed to Winston. Metadata is optional.
49+
//
4250
Loggly.prototype.log = function (level, msg, meta, callback) {
4351
var message = utils.clone(meta);
4452
message.level = level;

lib/winston/transports/riak.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
var riakjs = require('riak-js'),
1111
utils = require('./../utils');
12-
12+
13+
//
14+
// function Riak (options)
15+
// Constructor for the Riak transport object.
16+
//
1317
var Riak = exports.Riak = function (options) {
1418
options = options || {};
1519
this.client = riakjs.getClient(options);
@@ -19,6 +23,10 @@ var Riak = exports.Riak = function (options) {
1923
this.bucketName = options.bucketName || Date.now;
2024
};
2125

26+
//
27+
// function log (level, msg, [meta], callback)
28+
// Core logging method exposed to Winston. Metadata is optional.
29+
//
2230
Riak.prototype.log = function (level, msg, meta, callback) {
2331
var metac = utils.clone(meta);
2432
metac.level = level;

lib/winston/utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ var timestamp = exports.timestamp = function () {
4545
}
4646

4747
//
48-
// Generic logging function for returning timestamped strings
48+
// function log (level, msg, meta)
49+
// Generic logging function for returning timestamped strings
4950
//
5051
var log = exports.log = function (level, msg, meta) {
5152
var output = timestamp() + ' - ' + level + ': ' + msg;

usage.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ winston.add('loggly', {
2424
});
2525

2626
// Remove console (set by default)
27-
winston.remove('console');
28-
29-
winston.load('config-file.json');
27+
winston.remove(winston.transports.Console);
3028

3129
//
3230
// Remark: These statements are equivalent
@@ -42,17 +40,18 @@ winston.info('some message', { metadata: 'hi'});
4240

4341
var options = {
4442
emitErrs: false,
45-
transports: {
46-
'riak': winston.default,
47-
'loggly': {
43+
transports: [
44+
new (winston.transports.Riak)(),
45+
new (winston.transports.Loggly)({
4846
subdomain: 'winston',
4947
inputToken: 'really-long-thing-you-got-from-loggly',
5048
auth: {
5149
username: 'user',
5250
password: 'pass'
5351
}
54-
}
55-
}
52+
})
53+
]
5654
}
55+
5756
var logger = new (winston.Logger)(options);
5857
logger.log('info', { message: 'some message' });

0 commit comments

Comments
 (0)