index.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Type definitions for winston 3.0
  2. // Project: https://github.com/winstonjs/winston
  3. /// <reference types="node" />
  4. import * as stream from "stream";
  5. import * as logform from 'logform';
  6. import * as Transport from 'winston-transport';
  7. import * as Config from './lib/winston/config/index';
  8. import * as Transports from './lib/winston/transports/index';
  9. declare namespace winston {
  10. // Hoisted namespaces from other modules
  11. export import format = logform.format;
  12. export import config = Config;
  13. export import transports = Transports;
  14. interface ExceptionHandler {
  15. logger: Logger;
  16. handlers: Map<any, any>;
  17. catcher: Function | boolean;
  18. handle(...transports: Transport[]): void;
  19. unhandle(...transports: Transport[]): void;
  20. getAllInfo(err: string | Error): object;
  21. getProcessInfo(): object;
  22. getOsInfo(): object;
  23. getTrace(err: Error): object;
  24. new(logger: Logger): ExceptionHandler;
  25. }
  26. interface QueryOptions {
  27. rows?: number;
  28. limit?: number;
  29. start?: number;
  30. from?: Date;
  31. until?: Date;
  32. order?: "asc" | "desc";
  33. fields: any;
  34. }
  35. interface Profiler {
  36. logger: Logger;
  37. start: Date;
  38. done(info?: any): boolean;
  39. }
  40. type LogCallback = (error?: any, level?: string, message?: string, meta?: any) => void;
  41. interface LogEntry {
  42. level: string;
  43. message: string;
  44. [optionName: string]: any;
  45. }
  46. interface LogMethod {
  47. (level: string, message: string, callback: LogCallback): Logger;
  48. (level: string, message: string, meta: any, callback: LogCallback): Logger;
  49. (level: string, message: string, ...meta: any[]): Logger;
  50. (entry: LogEntry): Logger;
  51. }
  52. interface LeveledLogMethod {
  53. (message: string, callback: LogCallback): Logger;
  54. (message: string, meta: any, callback: LogCallback): Logger;
  55. (message: string, ...meta: any[]): Logger;
  56. (infoObject: object): Logger;
  57. }
  58. interface LoggerOptions {
  59. levels?: Config.AbstractConfigSetLevels;
  60. silent?: boolean;
  61. format?: logform.Format;
  62. level?: string;
  63. exitOnError?: Function | boolean;
  64. transports?: Transport[] | Transport;
  65. exceptionHandlers?: any;
  66. }
  67. interface Logger extends stream.Transform {
  68. silent: boolean;
  69. format: logform.Format;
  70. levels: Config.AbstractConfigSetLevels;
  71. level: string;
  72. transports: Transport[];
  73. exceptions: ExceptionHandler;
  74. profilers: object;
  75. exitOnError: Function | boolean;
  76. log: LogMethod;
  77. add(transport: Transport): Logger;
  78. remove(transport: Transport): Logger;
  79. clear(): Logger;
  80. close(): Logger;
  81. // for cli and npm levels
  82. error: LeveledLogMethod;
  83. warn: LeveledLogMethod;
  84. help: LeveledLogMethod;
  85. data: LeveledLogMethod;
  86. info: LeveledLogMethod;
  87. debug: LeveledLogMethod;
  88. prompt: LeveledLogMethod;
  89. http: LeveledLogMethod;
  90. verbose: LeveledLogMethod;
  91. input: LeveledLogMethod;
  92. silly: LeveledLogMethod;
  93. // for syslog levels only
  94. emerg: LeveledLogMethod;
  95. alert: LeveledLogMethod;
  96. crit: LeveledLogMethod;
  97. warning: LeveledLogMethod;
  98. notice: LeveledLogMethod;
  99. query(options?: QueryOptions, callback?: (err: Error, results: any) => void): any;
  100. stream(options?: any): NodeJS.ReadableStream;
  101. startTimer(): Profiler;
  102. profile(id: string | number): Logger;
  103. configure(options: LoggerOptions): void;
  104. new(options?: LoggerOptions): Logger;
  105. }
  106. interface Container {
  107. loggers: Map<string, Logger>;
  108. options: LoggerOptions;
  109. add(id: string, options?: LoggerOptions): Logger;
  110. get(id: string, options?: LoggerOptions): Logger;
  111. has(id: string): boolean;
  112. close(id?: string): void;
  113. new(options?: LoggerOptions): Container;
  114. }
  115. let version: string;
  116. let ExceptionHandler: ExceptionHandler;
  117. let Container: Container;
  118. let loggers: Container;
  119. let addColors: (target: Config.AbstractConfigSetColors) => any;
  120. let createLogger: (options?: LoggerOptions) => Logger;
  121. // Pass-through npm level methods routed to the default logger.
  122. let error: LeveledLogMethod;
  123. let warn: LeveledLogMethod;
  124. let info: LeveledLogMethod;
  125. let http: LeveledLogMethod;
  126. let verbose: LeveledLogMethod;
  127. let debug: LeveledLogMethod;
  128. let silly: LeveledLogMethod;
  129. // Other pass-through methods routed to the default logger.
  130. let log: LogMethod;
  131. let query: (options?: QueryOptions, callback?: (err: Error, results: any) => void) => any;
  132. let stream: (options?: any) => NodeJS.ReadableStream;
  133. let add: (transport: Transport) => Logger;
  134. let remove: (transport: Transport) => Logger;
  135. let clear: () => Logger;
  136. let startTimer: () => Profiler;
  137. let profile: (id: string | number) => Logger;
  138. let configure: (options: LoggerOptions) => void;
  139. let level: string;
  140. let exceptions: ExceptionHandler;
  141. let exitOnError: Function | boolean;
  142. // let default: object;
  143. }
  144. export = winston;