custom level not work in typescript
See original GitHub issuePlease tell us about your environment:
winston
version?-
winston@2
-
winston@3
-
- _
node -v
outputs:_v8.12.0 - Operating System? macOS
- Language? | TypeScript 3.1.3
What is the problem?
custom level not work in typescript 3.1.3
code
import winston from 'winston';
const myCustomLevels: winston.config.AbstractConfigSetLevels = {
foo: 0,
bar: 1,
baz: 2,
foobar: 3
};
const customLevelLogger = winston.createLogger({
levels: myCustomLevels,
transports: [
new winston.transports.Console({
level: 'foobar'
})
]
});
// [ts] Property 'foobar' does not exist on type 'Logger'.
customLevelLogger.foobar('some foobar level-ed message');
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Winston custom log levels typescript definitions - Stack Overflow
The definitions as currently written do not unfortunately allow for custom log levels. The simplest solution is to cast the returned logger ......
Read more >Advanced integration with custom typescript component ...
Advanced integration with custom typescript component (Implementation) In this tutorial, you'll inspect each individual TypeScript file in the tutorial project ...
Read more >CUSTOM ERRORS in TypeScript? - Advanced ... - YouTube
Become a TypeScript Wizard with Matt's upcoming TypeScript Course:https://www.mattpocock.com/Follow Matt on ...
Read more >Tasks in Visual Studio Code
You can create user level tasks that are not tied to a specific workspace or ... A tasks.json that configures the npm: run...
Read more >Documentation - Module Resolution - TypeScript
If that didn't work and if the module name is non-relative (and in the case of ... A node_modules folder can be on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another alternative is to just extend the
winston.Logger
interface and then cast the result ofcreateLogger
to your interface.It would be even better if each logger could infer levels from the
createLogger
call. That means if we exclude certain common levels from thelevels
config, we will get the proper compile-time error if we try calling that.For example, we could make it infer the levels in this example:
I’m happy to work on a PR when I get some free time.
Edit: I realize maybe this can’t be done since Winston can be augmented on the fly with
.configure()
😫