Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip colors from messages and metadata #18

Merged
merged 1 commit into from
Jul 3, 2014
Merged

Conversation

epd
Copy link
Contributor

@epd epd commented Jul 3, 2014

It would be useful to strip out the color escape codes (i.e. [33m) from the logs sent to Logstash. It looks like Winston exposes a string transform we can use here to do this: https://github.com/flatiron/winston/blob/ea8bb5b7b2c58274dc128e1942846c8f1c9c19ae/lib/winston/common.js#L129.

Would love to iterate on this if there is a better way; this is my first pass.

It would be useful to strip out the color escape codes (i.e. `[33m`) from the logs sent to Logstash. It looks like Winston exposes a string transform we can use here to do this: https://github.com/flatiron/winston/blob/ea8bb5b7b2c58274dc128e1942846c8f1c9c19ae/lib/winston/common.js#L129. Would love to iterate on this if there is a better way; this is my first pass.
jaakkos added a commit that referenced this pull request Jul 3, 2014
Strip colors from messages and metadata
@jaakkos jaakkos merged commit b5534aa into jaakkos:master Jul 3, 2014
@jaakkos
Copy link
Owner

jaakkos commented Jul 3, 2014

Thanks, I'll just push new version.

@epd epd deleted the patch-1 branch July 3, 2014 16:28
@nicobleiler
Copy link

This still seems to be a problem.

require('dotenv').config();
const winston = require('winston');
const LogstashTransport = require("winston-logstash/lib/winston-logstash-latest");
const os = require('os');

// Prepare logging
const logger = winston.createLogger({
    level: "debug",
    format: winston.format.combine(winston.format.simple(), winston.format.timestamp(), winston.format.colorize()),
    defaultMeta: {
        environment: process.env.NODE_ENV || "development",
        service: 'ephemeral',
        host: os.hostname(),
        version: require('./package.json').version,
    },
    transports: [
        new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
        new winston.transports.File({ filename: 'logs/combined.log' }),
        new winston.transports.Console(),
    ],
});

if (process.env.LOGSTASH_HOST && process.env.LOGSTASH_PORT && process.env.LOGSTASH_HOST) {
    logger.info("Using Logstash");
    logger.add(        
        new LogstashTransport({
            port: process.env.LOGSTASH_PORT,
            node_name: process.env.LOGSTASH_NODE_NAME,
            host: process.env.LOGSTASH_HOST,
            max_connect_retries: -1
        }),
    );
} else {
    logger.info("Missing ENV variables to use Logstash");
}

module.exports = {
    logger: logger
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants