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.

Attempt to write logs with no transports.

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs:
  • _Operating System? Linux
  • _Language? ES6/7

What is the problem?

Attempt to write logs with no transports on console.

[winston] Attempt to write logs with no transports {"message":"Hey man, I am here!","level":"debug"}
[winston] Attempt to write logs with no transports {"message":"App running on 3000","level":"info"}

What do you expect to happen instead?

Expect to write on console and combined.log and error.log files.

Other information

logger.js

import winston from 'winston'

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    //
    // - Write to all logs with level `info` and below to `combined.log` 
    // - Write all logs error (and below) to `error.log`.
    //
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
    new winston.transports.Console({ format: winston.format.json() })
  ]
})

winston.info('Hey man, I am here!')

export default logger

Usage on index.js

require('./lib/logger.js')
winston.info(`App running on ${port}`)

Obeservation error and combined.log has permission 777 event through is not the ideal.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:13
  • Comments:21

github_iconTop GitHub Comments

6reactions
lkashefcommented, Dec 8, 2019

@lukaswilkeer, Assuming that createLogger doesn’t already add the logger/stream to winston, just merely construct the logger.

Based on your code snippet, adding winston.add(logger) after you create your logger should solve the problem.

You could also add more streams, loggers and once you require winston in any part of the application, it should return the configured logger.

4reactions
lukaswilkeercommented, Dec 16, 2019
  1. It’s not a permission issue, actually I give the 777 to combined and error.log to be sure.
  2. Imports are correctly.
  3. Winston is up-to-date.
  4. I’m following the official example.

I created a repro script and winston works correctly. The problem where Uncaught errors inside the application. (Not reported or proper winston error). Don’t know the root cause. In this case, winston.add(logger) solved the problem of transports.

Closed issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attempt to write logs with no transports - using default logger ...
In winston 3 you need to create a logger object, then add transport s to it. Winston 3 has many examples, but to...
Read more >
How To Log Like A Boss With Node.js | by Eren Yatkin
[winston] Attempt to write logs with no transports {"message":"Test Log","level":"info"}. Because we have not configured it.
Read more >
Attempt to write logs with no transports – using default logger ...
Best Solution. In winston 3 you need to create a logger object, then add transport s to it.
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
Learn how to start logging with Winston in Node.js and go from basics to best ... Here are some custom transports that you...
Read more >
Winston Attempt to write logs with no transports
A transport for winston which logs to a rotating file. Logs can be rotated based on a date, size limit, and old logs...
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