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.

`log.log("warning", "message")` works, but `log.warning("message") doesn't

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • _node -v outputs: v10.16.0
  • _Operating System? macOS & Linux
  • _Language? TypeScript 3.3, JavaScript

What is the problem?

A call to log.log("warning", "message") works, but a call to log.warning("message") doesn’t. This is with a Console logger and syslog levels.

Online example of problem: https://repl.it/repls/LongtermCloudyCircles

const winston = require("winston");
winston.loggers.add("default");
const log = winston.loggers.get("default");
log.levels = winston.config.syslog.levels;
log.add(new winston.transports.Console());

log.log("warning", "named warning message");
log.warning("warning message");

Running that code will produce the following:

{"level":"warning","message":"named warning message"}
./scratch.js:8
log.warning("warning message");
    ^

TypeError: log.warning is not a function
    at Object.<anonymous> (/Users/cjbarth/meps/wol-castle/scratch.js:8:5)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

What do you expect to happen instead?

{“level”:“warning”,“message”:“named warning message”} {“level”:“warning”,“message”:“warning message”}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
wbtcommented, Jan 31, 2022

For those looking for a quick fix, try doing a project-wide find (in your own project) for log.warning( and replace it with log.warn(. I agree it would be a good idea to handle .warning more elegantly though.

1reaction
jleverenzcommented, Jan 27, 2020

Somewhat new to winston internals, but I believe this is due to how the example is setting levels. If not set during logger configuration, winston will not setup the logger prototype with the per-level convenience functions (log.warning)

However, if passed as configuration, log.warning is available:

const winston = require("winston");
winston.loggers.add("default", {
  levels: winston.config.syslog.levels
});
const log = winston.loggers.get("default");
log.add(new winston.transports.Console());

log.log("warning", "named warning message");
log.warning("warning message");

Thoughts? I’m thinking this is a non-issue, and setting levels via log.levels = is not intended to be supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log.LogMessage does not display in Visual Studio console
I have a Build Task, I'm trying to write message to the Visual Studio output console using Log.LogMessage but to no avail.
Read more >
log info doesn't show up on console but warn and error do
It prints warning and critical messages properly, but it does not print info and debug . getEffectiveLevel() shows the correct level. import ...
Read more >
7.5 - Types of Log Messages | STAT 480
In this section, we investigate three different kinds of messages —errors, warnings, and notes — that SAS displays in the log window.
Read more >
Logging HOWTO — Python 3.11.1 documentation
Logging is a means of tracking events that happen when some software runs. ... The INFO message doesn't appear because the default level...
Read more >
psychopy.logging - control what gets logged
Provides functions for logging error and other messages to one or more files ... Some warning messages and error messages are generated by...
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