Open OxyTJ opened 2 years ago
Side note, I had a thought that maybe it was because fatal
started at 0, so I incremented all of them by 1, but that did not make a difference, just fyi.
I also installed @types/winston
to no avail.
Using LoggerService.log('fatal', <message>);
for the time being.
Facing the same issue
Facing the same issue
Doesn't look like you can use fatal
or custom levels as methods, you'll have to do .log(<fatal-or-custom-level>, <message>);
.
Facing the same issue
Doesn't look like you can use
fatal
or custom levels as methods, you'll have to do.log(<fatal-or-custom-level>, <message>);
.
yes, it's working now thank you
Had the same issue using Typescript. If you don't use the default levels from the Winston npm package, Typescript will throw you an error. My code looks a bit different but after calling "createLogger()" try to add: "as winston.Logger & Record<keyof typeof LOG_LEVELS['levels'], winston.LeveledLogMethod>;"
Like that you can add whatever level you want, it's more a typescript issue than a Winston issue, when using JavaScript I don't face the same implications.
Take a look at my source, in case you need further explanation: https://stackoverflow.com/questions/53298354/winston-custom-log-levels-typescript-definitions
Had the same issue using Typescript. If you don't use the default levels from the Winston npm package, Typescript will throw you an error. My code looks a bit different but after calling "createLogger()" try to add: "as winston.Logger & Record<keyof typeof LOG_LEVELS['levels'], winston.LeveledLogMethod>;"
Like that you can add whatever level you want, it's more a typescript issue than a Winston issue, when using JavaScript I don't face the same implications.
Take a look at my source, in case you need further explanation: https://stackoverflow.com/questions/53298354/winston-custom-log-levels-typescript-definitions
Oh, I like this, I'll have to give it a look, thanks! Only concern I have - and again this is a TypeScript issue not Winston issue - is for my LoggerService
that I created, I install it in my other applications, and I have methods for allowing creating different log levels for each project, if it were ever required. So, it's basically a wrapper for winston and I'm not aware whether I could change the "as" statement dynamically at run time when the levels would be set in other applications. Rather than setting the levels through a .env
, for example, I import my installed service and then call a setLevels
method in the server index.ts
to apply any custom levels. Could remedy it by using .env
, but I'm inclined to only do that for my applications, not my packages.
But why would you want different log levels? Would it not be better to define a standard that applies to each application, ensuring they use the same set of log levels? When thinking about analysing incoming logs, I'd say that will help keeping it consistent. Feel free to share your opinion why I might be wrong.
You're not wrong at all, and that's what I've done. I do have a standard for all of my applications, in which the wrapper defaults to automatically. However, I still would like to build the package to be flexible enough to work for any other standards other than just mine. Package is private and most likely forever will be, it's soley for the sake of flexibility.
Oh, I see. Now it makes more sense to me. In case you find a solution, you could post it here.
🔎 Search Terms
Property 'fatal' does not exist on type 'Logger'
The problem
Custom
createLogger
logger with custom log levels receives aProperty 'fatal' does not exist on type 'Logger'
intellisense error forlogger.fatal
. All other log levels work just fine. Unfortunately, this is causingnpm run dev
to fail:What version of Winston presents the issue?
^3.8.1
What version of Node are you using?
v16.13.0
If this worked in a previous version of Winston, which was it?
N/A
Minimum Working Example
Additional information
No response