Skip to content

Commit

Permalink
chalk debug
Browse files Browse the repository at this point in the history
  • Loading branch information
openhoat committed Dec 13, 2015
1 parent 5665649 commit c234a7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ that = {
return typeof options.logger === 'function' || function (req, res, next) {
var reqInfo
, doLog = function (res) {
var contentLength = res.get('content-length');
log.http('%s - %s %s - %s - %s',
reqInfo.ip, reqInfo.method, reqInfo.url,
typeof res.statusCode !== 'undefined' ? res.statusCode : '?',
typeof contentLength !== 'undefined' ? contentLength : '?'
);
};
var contentLength = res.get('content-length');
log.http('%s - %s %s - %s - %s',
reqInfo.ip, reqInfo.method, reqInfo.url,
typeof res.statusCode !== 'undefined' ? res.statusCode : '?',
typeof contentLength !== 'undefined' ? contentLength : '?'
);
};
reqInfo = {
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
method: req.method,
Expand Down Expand Up @@ -127,9 +127,7 @@ that = {
if (process.env['HW_LOG_COLORS']) {
that.config.colors = process.env['HW_LOG_COLORS'] === 'true';
}
if (typeof that.config.colors === 'boolean') {
chalk.enabled = that.config.colors;
}
that.chalk = new chalk.constructor({enabled: typeof that.config.colors === 'boolean' ? that.config.colors : true});
if (!that.config.format) {
that.config.formatFile = path.resolve(path.join(__dirname, '..', 'templates'), that.config.formatFile || 'default.tpl');
if (!path.extname(that.config.formatFile)) {
Expand All @@ -143,7 +141,7 @@ that = {
} else if (typeof that.config.format === 'string') {
that.render = template(that.config.format, that.config.template);
that.buildLogMessage = function (data) {
return that.render({data: data, chalk: chalk, util: util, path: path, config: that.config});
return that.render({data: data, chalk: that.chalk, util: util, path: path, config: that.config});
};
} else {
throw new Error('format not supported');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hw-logger",
"version": "1.1.12",
"version": "1.1.13",
"description": "Efficient logger for node",
"main": "lib/logger.js",
"author": "Olivier Penhoat <openhoat@gmail.com> (http://headwood.net/)",
Expand Down

0 comments on commit c234a7e

Please sign in to comment.