logger.d.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. export declare enum LogLevel {
  2. ERROR = 0,
  3. WARN = 1,
  4. INFO = 2,
  5. DEBUG = 3,
  6. }
  7. export declare enum WriteTo {
  8. CONSOLE = 0,
  9. FILE = 1,
  10. BOTH = 2,
  11. NONE = 3,
  12. }
  13. /**
  14. * Logger class adds timestamp output, log levels, and identifiers to help
  15. * when debugging. Also could write to console, file, both, or none.
  16. */
  17. export declare class Logger {
  18. private id;
  19. static logLevel: LogLevel;
  20. static showTimestamp: boolean;
  21. static showId: boolean;
  22. static writeTo: WriteTo;
  23. static fd: any;
  24. static firstWrite: boolean;
  25. /**
  26. * Set up the write location. If writing to a file, get the file descriptor.
  27. * @param writeTo The enum for where to write the logs.
  28. * @param opt_logFile An optional parameter to override the log file location.
  29. */
  30. static setWrite(writeTo: WriteTo, opt_logFile?: string): void;
  31. /**
  32. * Creates a logger instance with an ID for the logger.
  33. * @constructor
  34. */
  35. constructor(id: string);
  36. /**
  37. * Log INFO
  38. * @param ...msgs multiple arguments to be logged.
  39. */
  40. info(...msgs: any[]): void;
  41. /**
  42. * Log DEBUG
  43. * @param ...msgs multiple arguments to be logged.
  44. */
  45. debug(...msgs: any[]): void;
  46. /**
  47. * Log WARN
  48. * @param ...msgs multiple arguments to be logged.
  49. */
  50. warn(...msgs: any[]): void;
  51. /**
  52. * Log ERROR
  53. * @param ...msgs multiple arguments to be logged.
  54. */
  55. error(...msgs: any[]): void;
  56. /**
  57. * For the log level set, check to see if the messages should be logged.
  58. * @param logLevel The log level of the message.
  59. * @param msgs The messages to be logged
  60. */
  61. log_(logLevel: LogLevel, msgs: any[]): void;
  62. /**
  63. * Format with timestamp, log level, identifier, and message and log to
  64. * specified medium (console, file, both, none).
  65. * @param logLevel The log level of the message.
  66. * @param msgs The messages to be logged.
  67. */
  68. print_(logLevel: LogLevel, msgs: any[]): void;
  69. /**
  70. * Get a timestamp formatted with [hh:mm:ss]
  71. * @param writeTo The enum for where to write the logs.
  72. * @return The string of the formatted timestamp
  73. */
  74. static timestamp_(writeTo: WriteTo): string;
  75. /**
  76. * Get the identifier of the logger as '/<id>'
  77. * @param logLevel The log level of the message.
  78. * @param writeTo The enum for where to write the logs.
  79. * @return The string of the formatted id
  80. */
  81. static id_(logLevel: LogLevel, id: string, writeTo: WriteTo): string;
  82. /**
  83. * Get the log level formatted with the first letter. For info, it is I.
  84. * @param logLevel The log level of the message.
  85. * @param writeTo The enum for where to write the logs.
  86. * @return The string of the formatted log level
  87. */
  88. static level_(logLevel: LogLevel, id: string, writeTo: WriteTo): string;
  89. /**
  90. * Convert the list of messages to a single string message.
  91. * @param msgs The list of messages.
  92. * @return The string of the formatted messages
  93. */
  94. static msgToFile_(msgs: any[]): string;
  95. }