|
2 | 2 | // This product includes software developed at Datadog (https://www.datadoghq.com/). |
3 | 3 | // Copyright 2019-Present Datadog, Inc. |
4 | 4 |
|
| 5 | +import { getSendLog } from '@dd/core/helpers/log'; |
5 | 6 | import { cleanPluginName } from '@dd/core/helpers/plugins'; |
6 | 7 | import { formatDuration } from '@dd/core/helpers/strings'; |
7 | 8 | import type { |
@@ -41,7 +42,7 @@ export const getLogFn = ( |
41 | 42 | ): LogFn => { |
42 | 43 | // Will remove any "datadog-" prefix and "-plugin" suffix in the name string. |
43 | 44 | const cleanedName = cleanName(name); |
44 | | - return (text: any, type: LogLevel = 'debug') => { |
| 45 | + return (text, type = 'debug', { forward } = {}) => { |
45 | 46 | // By default (debug) we print dimmed. |
46 | 47 | let color = c.dim; |
47 | 48 | let logFn = console.log; |
@@ -77,6 +78,12 @@ export const getLogFn = ( |
77 | 78 | stores.warnings.push(content); |
78 | 79 | } |
79 | 80 |
|
| 81 | + if (forward) { |
| 82 | + stores.queue.push( |
| 83 | + getSendLog(data)({ message: content, context: { plugin: name, status: type } }), |
| 84 | + ); |
| 85 | + } |
| 86 | + |
80 | 87 | // Only log if the log level is high enough. |
81 | 88 | if (logPriority[type] >= logPriority[logLevel]) { |
82 | 89 | logFn(`${color(prefix)} ${content}`); |
@@ -197,9 +204,9 @@ export const getLoggerFactory = |
197 | 204 | return logger(`${cleanName(name)}${NAME_SEP}${subName}`); |
198 | 205 | }, |
199 | 206 | time: getTimeLogger(name, stores.timings, log), |
200 | | - error: (text: any) => log(text, 'error'), |
201 | | - warn: (text: any) => log(text, 'warn'), |
202 | | - info: (text: any) => log(text, 'info'), |
203 | | - debug: (text: any) => log(text, 'debug'), |
| 207 | + error: (text: any, opts?: LogOptions) => log(text, 'error', opts), |
| 208 | + warn: (text: any, opts?: LogOptions) => log(text, 'warn', opts), |
| 209 | + info: (text: any, opts?: LogOptions) => log(text, 'info', opts), |
| 210 | + debug: (text: any, opts?: LogOptions) => log(text, 'debug', opts), |
204 | 211 | }; |
205 | 212 | }; |
0 commit comments