Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added simple colorize options #371

Closed
wants to merge 7 commits into from

4 participants

@MichielDeMey

Hi

We've added a couple of more choices for the colorize option:

  • 'level', which will only colorize the level (same as true)
  • 'message', which will only colorize the message
  • 'all', which will colorize both the level and the message

The default behavior is kept, simply set colorize to true to colorize the level only, set it to false to disable colors.

@indexzero
Owner

Thank you for your contribution. This is much cleaner than #363. Will go into winston@0.9.0 Also worth noting that this option will be dropped in winston@1.0.0 in favor of custom Formatters.

@indexzero indexzero added the v0.9.0 label
@indexzero
Owner

Finally got this cherry-picked & squashed onto master. In the future you should check out git rebase -i, it will make your git history a lot cleaner :+1:

@indexzero indexzero closed this
@adius

Maybe next time you can also update the documentation. Just spend half an hour wondering why colorize: 'true' doesn't work.

@adius

Ah colorize: true still works, but colorize: 'true' was wrong all along.
Pull request for fixing this: #547

@MichielDeMey

Nice catch! :+1:

@monolithed

Please update the README file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2014
  1. @MichielDeMey

    Changed package file

    MichielDeMey authored
  2. @MichielDeMey

    Added the options to colorize only the level, only the message or all.

    MichielDeMey authored
    Default behavior is kept. Using true will only colorize the level and false will not colorize anything.
  3. @MichielDeMey

    Added the options to colorize only the level, only the message or all.

    MichielDeMey authored
    Default behavior is kept. Using true will only colorize the level and false will not colorize anything.
  4. @MichielDeMey
  5. @MichielDeMey
  6. @MichielDeMey
  7. @MichielDeMey
This page is out of date. Refresh to see the latest.
View
11 examples/color-message.js
@@ -0,0 +1,11 @@
+var winston = require('../lib/winston');
+
+var logger = module.exports = new (winston.Logger)({
+ transports: [
+ new (winston.transports.Console)({
+ colorize: 'all'
+ })
+ ]
+});
+
+logger.log('info', 'This is an information message.');
View
8 lib/winston/common.js
@@ -145,7 +145,7 @@ exports.log = function (options) {
if (timestamp) {
output.timestamp = timestamp;
}
-
+
if (options.logstash === true) {
// use logstash format
var logstashOutput = {};
@@ -175,10 +175,10 @@ exports.log = function (options) {
}
output = timestamp ? timestamp + ' - ' : '';
- output += options.colorize ? config.colorize(options.level) : options.level;
+ output += options.colorize === 'all' || options.colorize === 'level' || options.colorize === true ? config.colorize(options.level) : options.level;
output += ': ';
output += options.label ? ('[' + options.label + '] ') : '';
- output += options.message;
+ output += options.colorize === 'all' || options.colorize === 'message' ? config.colorize(options.level, options.message) : options.message;
if (meta !== null && meta !== undefined) {
if (meta && meta instanceof Error && meta.stack) {
@@ -307,7 +307,7 @@ exports.tailFile = function tail(options, callback) {
if (options.start === -1) {
delete options.start;
}
-
+
stream.on('data', function (data) {
var data = (buff + data).split(/\n+/),
l = data.length - 1,
View
6 lib/winston/config.js
@@ -15,8 +15,10 @@ config.addColors = function (colors) {
mixin(allColors, colors);
};
-config.colorize = function (level) {
- var colorized = level;
+config.colorize = function (level, message) {
+ if (typeof message === 'undefined') message = level;
+
+ var colorized = message;
if (allColors[level] instanceof Array) {
for (var i = 0, l = allColors[level].length; i < l; ++i) {
colorized = colorized[allColors[level][i]];
Something went wrong with that request. Please try again.