| 27 | } |
| 28 | |
| 29 | export class OtelTaskLogger implements TaskLogger { |
| 30 | private readonly _level: number; |
| 31 | |
| 32 | constructor(private readonly _config: TaskLoggerConfig) { |
| 33 | this._level = logLevels.indexOf(_config.level); |
| 34 | } |
| 35 | |
| 36 | debug(message: string, properties?: Record<string, unknown>) { |
| 37 | if (this._level < 4) return; // ["none", "error", "warn", "info", "debug"]; |
| 38 | |
| 39 | this.#emitLog(message, this.#getTimestampInHrTime(), "debug", SeverityNumber.DEBUG, properties); |
| 40 | } |
| 41 | |
| 42 | log(message: string, properties?: Record<string, unknown>) { |
| 43 | if (this._level < 3) return; // ["none", "error", "warn", "info", "debug"]; |
| 44 | |
| 45 | this.#emitLog(message, this.#getTimestampInHrTime(), "log", SeverityNumber.INFO, properties); |
| 46 | } |
| 47 | |
| 48 | info(message: string, properties?: Record<string, unknown>) { |
| 49 | if (this._level < 3) return; // ["none", "error", "warn", "info", "debug"]; |
| 50 | |
| 51 | this.#emitLog(message, this.#getTimestampInHrTime(), "info", SeverityNumber.INFO, properties); |
| 52 | } |
| 53 | |
| 54 | warn(message: string, properties?: Record<string, unknown>) { |
| 55 | if (this._level < 2) return; // ["none", "error", "warn", "info", "debug"]; |
| 56 | |
| 57 | this.#emitLog(message, this.#getTimestampInHrTime(), "warn", SeverityNumber.WARN, properties); |
| 58 | } |
| 59 | |
| 60 | error(message: string, properties?: Record<string, unknown>) { |
| 61 | if (this._level < 1) return; // ["none", "error", "warn", "info", "debug"]; |
| 62 | |
| 63 | this.#emitLog(message, this.#getTimestampInHrTime(), "error", SeverityNumber.ERROR, properties); |
| 64 | } |
| 65 | |
| 66 | #emitLog( |
| 67 | message: string, |
| 68 | timestamp: ClockTime, |
| 69 | severityText: string, |
| 70 | severityNumber: SeverityNumber, |
| 71 | properties?: Record<string, unknown> |
| 72 | ) { |
| 73 | let attributes: Attributes = { ...flattenAttributes(safeJsonProcess(properties)) }; |
| 74 | |
| 75 | const icon = iconStringForSeverity(severityNumber); |
| 76 | if (icon !== undefined) { |
| 77 | attributes[SemanticInternalAttributes.STYLE_ICON] = icon; |
| 78 | } |
| 79 | |
| 80 | this._config.logger.emit({ |
| 81 | severityNumber, |
| 82 | severityText, |
| 83 | body: message, |
| 84 | attributes, |
| 85 | timestamp, |
| 86 | }); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…