Ability to extend Logger class.
See original GitHub issueWhat is the problem?
I am trying to extend winston logger with custom methods on typescript. Currently it can only be done via as any
and assigning properties to the object manually. Moreover, methods like Logger#child
require to be improved.
Here is how it looks like:
interface LoggerExtras {
benchmark: Benchmark;
child(options: Record<string, any>): this;
}
type Logger = winston.Logger & LoggerExtras;
const logger: Logger = createLogger() as any;
logger.benchmark = ...
export default logger;
What’s the feature?
Ideally, I want to be able to extend Logger
in a pretty OOP way without manual property assignment manipulations like:
class MyLogger extends winston.Logger {
benchmark(...) {
....
}
}
export default new MyLogger(options);
Is it possible to add such a functionality and ensure typescript is supported?
What problem is the feature intended to solve?
Make winston logger more extensible in a clear way that is common for OOP language.
Is the absence of this feature blocking you or your team? If so, how?
It is not a blockers as there are hacks to achieve that.
Is this feature similar to an existing feature in another tool?
Yes, this feature is common feature in any OOP friendly logger where you can just use inheritance as a pattern.
It is very unusual that making Logger
is done through a factory method but not a constructor. Most loggers just expose a Logger
class to you like so: https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html
Is this a feature you’re prepared to implement, with support from us?
Yes.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5
Top GitHub Comments
I found a not elegant solution …
That works for me, but I don’t like use @ts-ignore and extends by a function. Note: If you remove @ts-ignore, you got an error…
I’m just reaching for it deep into the package