| 120 | */ |
| 121 | @Injectable() |
| 122 | export class ConsoleLogger implements LoggerService { |
| 123 | /** |
| 124 | * The options of the logger. |
| 125 | */ |
| 126 | protected options: ConsoleLoggerOptions; |
| 127 | /** |
| 128 | * The context of the logger (can be set manually or automatically inferred). |
| 129 | */ |
| 130 | protected context?: string; |
| 131 | /** |
| 132 | * The original context of the logger (set in the constructor). |
| 133 | */ |
| 134 | protected originalContext?: string; |
| 135 | /** |
| 136 | * The options used for the "inspect" method. |
| 137 | */ |
| 138 | protected inspectOptions: InspectOptions; |
| 139 | /** |
| 140 | * The last timestamp at which the log message was printed. |
| 141 | */ |
| 142 | protected static lastTimestampAt?: number; |
| 143 | |
| 144 | constructor(); |
| 145 | constructor(context: string); |
| 146 | constructor(options: ConsoleLoggerOptions); |
| 147 | constructor(context: string, options: ConsoleLoggerOptions); |
| 148 | constructor( |
| 149 | @Optional() |
| 150 | contextOrOptions?: string | ConsoleLoggerOptions, |
| 151 | @Optional() |
| 152 | options?: ConsoleLoggerOptions, |
| 153 | ) { |
| 154 | // eslint-disable-next-line prefer-const |
| 155 | let [context, opts] = isString(contextOrOptions) |
| 156 | ? [contextOrOptions, options] |
| 157 | : options |
| 158 | ? [undefined, options] |
| 159 | : [contextOrOptions?.context, contextOrOptions]; |
| 160 | |
| 161 | opts = opts ?? {}; |
| 162 | opts.logLevels ??= DEFAULT_LOG_LEVELS; |
| 163 | opts.colors ??= opts.colors ?? (opts.json ? false : isColorAllowed()); |
| 164 | opts.prefix ??= 'Nest'; |
| 165 | |
| 166 | this.options = opts; |
| 167 | this.inspectOptions = this.getInspectOptions(); |
| 168 | |
| 169 | if (context) { |
| 170 | this.context = context; |
| 171 | this.originalContext = context; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Write a 'log' level log, if the configured level allows for it. |
| 177 | * Prints to `stdout` with newline. |
| 178 | */ |
| 179 | log(message: any, context?: string): void; |
nothing calls this directly
no outgoing calls
no test coverage detected