Refactor logging implementation and remove console log statements

This commit is contained in:
Simon Larsen 2024-04-23 10:22:58 +01:00
parent c6b47c3a1b
commit 7574d3921a
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
2 changed files with 12 additions and 6 deletions

View File

@ -21,6 +21,9 @@ export default class logger {
LogLevel === ConfigLogLevel.DEBUG ||
LogLevel === ConfigLogLevel.INFO
) {
// eslint-disable-next-line no-console
console.info(message);
this.emit({
body: message,
severityNumber: SeverityNumber.INFO,
@ -35,6 +38,9 @@ export default class logger {
LogLevel === ConfigLogLevel.WARN ||
LogLevel === ConfigLogLevel.ERROR
) {
// eslint-disable-next-line no-console
console.error(message);
this.emit({
body: message,
severityNumber: SeverityNumber.ERROR,
@ -48,6 +54,9 @@ export default class logger {
LogLevel === ConfigLogLevel.INFO ||
LogLevel === ConfigLogLevel.WARN
) {
// eslint-disable-next-line no-console
console.warn(message);
this.emit({
body: message,
severityNumber: SeverityNumber.WARN,
@ -57,6 +66,9 @@ export default class logger {
public static debug(message: LogBody): void {
if (LogLevel === ConfigLogLevel.DEBUG) {
// eslint-disable-next-line no-console
console.debug(message);
this.emit({
body: message,
severityNumber: SeverityNumber.DEBUG,

View File

@ -8,9 +8,7 @@ import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentation
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
import {
BatchLogRecordProcessor,
ConsoleLogRecordExporter,
LoggerProvider,
SimpleLogRecordProcessor,
} from '@opentelemetry/sdk-logs';
import URL from 'Common/Types/API/URL';
import { SpanExporter } from '@opentelemetry/sdk-trace-node';
@ -135,10 +133,6 @@ export default class Telemetry {
);
}
loggerProvider.addLogRecordProcessor(
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
);
logs.setGlobalLoggerProvider(loggerProvider);
this.logger = logs.getLogger('default');