Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#8472 from MugeSo/winston-fix-metho…
Browse files Browse the repository at this point in the history
…ds-argument

Winston fix methods argument
  • Loading branch information
horiuchi committed Mar 23, 2016
2 parents b14601a + e1bc35c commit d4121d7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
12 changes: 12 additions & 0 deletions winston/winston-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ winston.exitOnError = bool;

winston.log(str, str);
winston.log(str, str, metadata);
winston.log(str, str, metadata, metadata, metadata);
winston.debug(str);
winston.debug(str, metadata);
winston.debug(str, metadata, metadata, metadata);
winston.info(str);
winston.info(str, metadata);
winston.info(str, metadata, metadata, metadata);
winston.warn(str);
winston.warn(str, metadata);
winston.warn(str, metadata, metadata, metadata);
winston.error(str);
winston.error(str, metadata);
winston.error(str, metadata, metadata, metadata);

winston.query(queryOptions, (err: Error, results: any): void => {

Expand All @@ -94,6 +99,7 @@ winston.query((err: Error, results: any): void => {

logger = winston.add(transport, transportOptions);
logger = winston.remove(transport);
logger = winston.add(transport, {filename: 'path/to/file.log'});

winston.clear();
logger = winston.profile(str, str, metadata, (err: Error, level: string, msg: string, meta: any):void => {
Expand All @@ -118,14 +124,19 @@ readableStream.on('log', function (log:any):void {
logger = logger.extend(obj);
logger.log(str, str);
logger.log(str, str, metadata);
logger.log(str, str, metadata, metadata, metadata);
logger.debug(str);
logger.debug(str, metadata);
logger.debug(str, metadata, metadata, metadata);
logger.info(str);
logger.info(str, metadata);
logger.info(str, metadata, metadata, metadata);
logger.warn(str);
logger.warn(str, metadata);
logger.warn(str, metadata, metadata, metadata);
logger.error(str);
logger.error(str, metadata);
logger.error(str, metadata, metadata, metadata);

logger.query(queryOptions, (err: Error, results: any): void => {

Expand All @@ -140,6 +151,7 @@ logger.handleExceptions(transport);
logger.unhandleExceptions(transport);
logger = logger.add(transport, transportOptions, bool);
logger = logger.add(transport);
logger = logger.add(transport, {filename: 'path/to/file.log'});

logger.clear();
logger = logger.remove(transport);
Expand Down
70 changes: 36 additions & 34 deletions winston/winston.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,12 @@ declare module "winston" {
export var exitOnError: boolean;
export var level: string;

export function log(level: string, msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export function log(level: string, msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export var log: LogMethod;

export function debug(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export function debug(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;

export function info(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export function info(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;

export function warn(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export function warn(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;

export function error(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export function error(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
export var debug: LeveledLogMethod;
export var info: LeveledLogMethod;
export var warn: LeveledLogMethod;
export var error: LeveledLogMethod;

export function query(options: QueryOptions, callback?: (err: Error, results: any) => void): any;
export function query(callback: (err: Error, results: any) => void): any;
Expand Down Expand Up @@ -113,20 +105,12 @@ declare module "winston" {

extend(target: any): LoggerInstance;

log(level: string, msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
log(level: string, msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;

debug(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
debug(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
log: LogMethod;

info(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
info(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;

warn(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
warn(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;

error(msg: string, meta: any, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
error(msg: string, callback?: (err: Error, level: string, msg: string, meta: any) => void): LoggerInstance;
debug: LeveledLogMethod;
info: LeveledLogMethod;
warn: LeveledLogMethod;
error: LeveledLogMethod;

query(options: QueryOptions, callback?: (err: Error, results: any) => void): any;
query(callback: (err: Error, results: any) => void): any;
Expand Down Expand Up @@ -225,7 +209,9 @@ declare module "winston" {
Webhook: WebhookTransportInstance;
}

export interface TransportOptions {
export type TransportOptions = ConsoleTransportOptions|DailyRotateFileTransportOptions|FileTransportOptions|HttpTransportOptions|MemoryTransportOptions|WebhookTransportOptions|WinstonModuleTransportOptions;

export interface GenericTransportOptions {
level?: string;
silent?: boolean;
raw?: boolean;
Expand Down Expand Up @@ -258,12 +244,12 @@ declare module "winston" {
path?: string;
}

export interface ConsoleTransportOptions extends TransportOptions, GenericTextTransportOptions {
export interface ConsoleTransportOptions extends GenericTransportOptions, GenericTextTransportOptions {
logstash?: boolean;
debugStdout?: boolean;
}

export interface DailyRotateFileTransportOptions extends TransportOptions, GenericTextTransportOptions {
export interface DailyRotateFileTransportOptions extends GenericTransportOptions, GenericTextTransportOptions {
logstash?: boolean;
maxsize?: number;
maxFiles?: number;
Expand All @@ -279,7 +265,7 @@ declare module "winston" {
stream?: NodeJS.WritableStream;
}

export interface FileTransportOptions extends TransportOptions, GenericTextTransportOptions {
export interface FileTransportOptions extends GenericTransportOptions, GenericTextTransportOptions {
logstash?: boolean;
maxsize?: number;
rotationFormat?: boolean;
Expand All @@ -297,14 +283,14 @@ declare module "winston" {
stream?: NodeJS.WritableStream;
}

export interface HttpTransportOptions extends TransportOptions, GenericNetworkTransportOptions {
export interface HttpTransportOptions extends GenericTransportOptions, GenericNetworkTransportOptions {
ssl?: boolean;
}

export interface MemoryTransportOptions extends TransportOptions, GenericTextTransportOptions {
export interface MemoryTransportOptions extends GenericTransportOptions, GenericTextTransportOptions {
}

export interface WebhookTransportOptions extends TransportOptions, GenericNetworkTransportOptions {
export interface WebhookTransportOptions extends GenericTransportOptions, GenericNetworkTransportOptions {
method?: string;
ssl?: {
key?: any;
Expand All @@ -313,7 +299,7 @@ declare module "winston" {
};
}

export interface WinstonModuleTransportOptions extends TransportOptions {
export interface WinstonModuleTransportOptions extends GenericTransportOptions {
[optionName: string]: any;
}

Expand All @@ -332,4 +318,20 @@ declare module "winston" {
start: Date;
done: (msg: string) => LoggerInstance;
}

interface LogMethod {
(level: string, msg: string, callback: LogCallback): LoggerInstance;
(level: string, msg: string, meta: any, callback: LogCallback): LoggerInstance;
(level: string, msg: string, ... meta: any[]): LoggerInstance;
}

interface LeveledLogMethod {
(msg: string, callback: LogCallback): LoggerInstance;
(msg: string, meta: any, callback: LogCallback): LoggerInstance;
(msg: string, ... meta: any[]): LoggerInstance;
}

interface LogCallback {
(error?: any, level?: string, msg?: string, meta?:any): void;
}
}

0 comments on commit d4121d7

Please sign in to comment.