Skip to content

Commit

Permalink
Fix bugs in createLogger type (#1807)
Browse files Browse the repository at this point in the history
* fix createLogger type

* fix to follow master
  • Loading branch information
Mizumaki authored Jun 22, 2020
1 parent 0e1c812 commit ef97171
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ declare namespace winston {
[optionName: string]: any;
}

interface LogMethod {
interface LogMethod {
(level: string, message: string, callback: LogCallback): Logger;
(level: string, message: string, meta: any, callback: LogCallback): Logger;
(level: string, message: string, ...meta: any[]): Logger;
Expand All @@ -74,8 +74,8 @@ declare namespace winston {
(infoObject: object): Logger;
}

interface LoggerOptions {
levels?: Config.AbstractConfigSetLevels;
interface LoggerOptions<T extends Config.AbstractConfigSetLevels = Config.AbstractConfigSetLevels> {
levels?: T;
silent?: boolean;
format?: logform.Format;
level?: string;
Expand All @@ -86,7 +86,29 @@ declare namespace winston {
exceptionHandlers?: any;
}

interface Logger extends NodeJSStream.Transform {
type DefaulLevels = {
// for cli and npm levels
error: number;
warn: number;
help: number;
data: number;
info: number;
debug: number;
prompt: number;
http: number;
verbose: number;
input: number;
silly: number;

// for syslog levels only
emerg: number;
alert: number;
crit: number;
warning: number;
notice: number;
}

type Logger<T extends Config.AbstractConfigSetLevels = DefaulLevels> = NodeJSStream.Transform & {
silent: boolean;
format: logform.Format;
levels: Config.AbstractConfigSetLevels;
Expand All @@ -103,26 +125,6 @@ declare namespace winston {
clear(): Logger;
close(): Logger;

// for cli and npm levels
error: LeveledLogMethod;
warn: LeveledLogMethod;
help: LeveledLogMethod;
data: LeveledLogMethod;
info: LeveledLogMethod;
debug: LeveledLogMethod;
prompt: LeveledLogMethod;
http: LeveledLogMethod;
verbose: LeveledLogMethod;
input: LeveledLogMethod;
silly: LeveledLogMethod;

// for syslog levels only
emerg: LeveledLogMethod;
alert: LeveledLogMethod;
crit: LeveledLogMethod;
warning: LeveledLogMethod;
notice: LeveledLogMethod;

query(options?: QueryOptions, callback?: (err: Error, results: any) => void): any;
stream(options?: any): NodeJS.ReadableStream;

Expand All @@ -142,7 +144,7 @@ declare namespace winston {
isSillyEnabled(): boolean;

new(options?: LoggerOptions): Logger;
}
} & {[K in keyof T]: LeveledLogMethod;}

interface Container {
loggers: Map<string, Logger>;
Expand All @@ -162,7 +164,7 @@ declare namespace winston {
let loggers: Container;

let addColors: (target: Config.AbstractConfigSetColors) => any;
let createLogger: (options?: LoggerOptions) => Logger;
let createLogger: <T extends Config.AbstractConfigSetLevels = DefaulLevels>(options?: LoggerOptions<T>) => Logger<T>;

// Pass-through npm level methods routed to the default logger.
let error: LeveledLogMethod;
Expand Down

0 comments on commit ef97171

Please sign in to comment.