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.

transports.File stops logger without any error message

See original GitHub issue

I’m trying to use transports.File to save log file in loop with logger. After several logs print out it stops to write log to file and print nothing in console without any error message.

Here is my test code:

import winston from 'winston'

const winstonConfig = {
  level: 'debug',
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({
      filename:  'file/path/to/combined.log',
      maxsize: 10 * 1024 * 1024,
      maxFiles: 10
    })
  ]
}
let logger = winston.createLogger(winstonConfig)

for(let i=0; i<10000; i++){
  logger.debug(i)
}

Is it stdout buffer issue?

I’m using version 3.0.0-rc1 with node:8-alpine image in docker container

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:30 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jansteuercommented, Apr 10, 2018

@rcoedo commit fixes the issue but there is still an issue with formatting which I think is related to this.

const winston = require('winston')

const winstonConfig = {
  level: 'debug',
  transports: [
    new winston.transports.Console({
      format: winston.format.printf(info => `${info.level}: ${info.message}`)
    }),
    new winston.transports.File({
      filename: 'winston.log',
      maxsize: 10 * 1024 * 1024,
      maxFiles: 10,
      format: winston.format.printf(info => `${info.level}: ${info.message}`)
    })
  ]
}
const logger = winston.createLogger(winstonConfig)

for (let i = 0; i < 10000; i++) {
  logger.debug(i)
}

Produces this output to a file:

....
debug: 2600
debug: 2601
debug: 2602
debug: 2603
debug: 2604
debug: 2605
debug: 2606
{"message":2607,"level":"debug"}
{"message":2608,"level":"debug"}
{"message":2609,"level":"debug"}
{"message":2610,"level":"debug"}
{"message":2611,"level":"debug"}
{"message":2612,"level":"debug"}
{"message":2613,"level":"debug"}
{"message":2614,"level":"debug"}
{"message":2615,"level":"debug"}
{"message":2616,"level":"debug"}
{"message":2617,"level":"debug"}
{"message":2618,"level":"debug"}
{"message":2619,"level":"debug"}
{"message":2620,"level":"debug"}
{"message":2621,"level":"debug"}
debug: 2622
debug: 2623
debug: 2624
debug: 2625
debug: 2626
debug: 2627
debug: 2628
.....

Output in the console is formatted correctly.

2reactions
rcoedocommented, Jun 27, 2018

I think this still happens when using the tailable: true option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Winston not logging at any log level, what could be wrong?
On the new production server, Winston logs the very first log message per .js file, period. It stops logging after that, and changing...
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
log file, but a separate app-error.log will also be created and it will contain only error messages. Note that the level property on...
Read more >
Winston - Best of JS
For example, one may want error logs to be stored in a persistent remote ... transports, [] (No transports), Set of logging targets...
Read more >
Node.js Logging with Winston - Reflectoring
log file, while only the error messages would be saved in an error.log file and the console transport will log messages to the...
Read more >
Complete Winston Logger Guide With Hands-on Examples
By default, the log message is not formatted and is printed as a ... 30 transports options, which include logging out into a...
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