question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transport Formatter not called/used.

See original GitHub issue

This might be more of a question than an ‘issue’. I am trying to use a custom formatter with a logging transport. It seems that the formatter function is ignored in my simple test. I’ve taken and slightly modified the example from the README:

'use strict';
var winston = require('winston');
var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.Console)({
            timestamp: function() {
                return Date.now();
            },
            formatter: function(options) {
                // Return string will be passed to logger.
                return 'MEOW!';
            }
        })
    ]
});
logger.info('Data to log.');

I am expecting the output (to stdout in this case) to be: “MEOW” Instead the output is:“1422632922024 - info: Data to log.” Which, I believe, is the default. Am I missing something?

Thanks!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
npanonecommented, Jun 7, 2016

Just ran into this and came up with a work around that worked out for me.

var logger = new winston.Logger({
    transports: [
        new (winston.transports.File)({
            filename: path,
            json: true,
            stringify: function (options) {
                return  <formatted string>;
            }
        })
    ]
});
1reaction
liamzhcommented, Feb 18, 2016

@calebbrewer try this?

logger = new (winston.Logger)({
  transports: [
    new (winston.transports.File)({
      json: false,
      filename: path,
      formatter: (options) ->
        options.message
    })
  ]
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Log Full Stack Trace with Winston 3?
For winston version 3.2.0+ , following will add stacktrace to log output: import { createLogger, format, transports } from 'winston'; ...
Read more >
How to Comply with Federal Hazardous Materials Regulations
This document provides only a general overview of the requirements for transporting hazardous materials by highway.
Read more >
JSON - Wikipedia
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of ......
Read more >
Logging with Winston and Node.js - Section.io
This article explain logging within the context of Winston. Winston processes your app activities and generate useful information into a log ...
Read more >
logging in JavaScript with Winston.js - ZetCode
format, winston.format.json, the format of log messages. transports, no transports, set of logging destinations for log messages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found