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

Variable Program String #77

Open
phuze opened this issue Dec 11, 2017 · 1 comment
Open

Variable Program String #77

phuze opened this issue Dec 11, 2017 · 1 comment

Comments

@phuze
Copy link

phuze commented Dec 11, 2017

I'm looking to pass an additional string along with each log message so as to dynamically define the program. Any suggestions how could I go about doing that?

Example:

var winston = require('winston');
require('winston-papertrail').Papertrail;

var winstonPapertrail = new winston.transports.Papertrail({
    host: 'logs12345.papertrailapp.com',
    port: 12345,
    program: 'PINEAPPLES_ARE_BLUE'
});

var logger = new winston.Logger({ transports: [winstonPapertrail] });

logger.info('This is my log message', 'PINEAPPLES_ARE_BLUE');

@phuze phuze changed the title Custom Data Variable Program String Dec 11, 2017
@phuze
Copy link
Author

phuze commented Dec 12, 2017

Thanks to help from the Papertrail team, they recommended trying to set the program name as such:

winstonPapertrail.program = 'PINEAPPLES_ARE_BLUE'

Success! Based on this, I opted to implement a wrapper function to accomplish my goal of variably setting the program name.

// papertrail remote logging
var winston = require('winston');
require('winston-papertrail').Papertrail;

var winstonPapertrail = new winston.transports.Papertrail({
    host: 'logs12345.papertrailapp.com',
    port: 12345,
    colorize: true
});

var winstonLogger = new winston.Logger({ transports: [winstonPapertrail] });

function logger(programName, message) {
    winstonPapertrail.program = programName;
    winstonLogger.info(message);
}

I then simply create log lines like this:

logger('program name 1', 'some message')
logger('program name 2', 'another message')
etc...

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

No branches or pull requests

1 participant