From 1a73fcd0c879f2bb70e0c431e110c8d601ff754d Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 19 Dec 2024 07:57:15 +0100 Subject: [PATCH] fix: Adjust log level for BiDi events (#2505) --- lib/commands/bidi/models.ts | 18 ++++++++++++++++-- lib/commands/bidi/types.ts | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/commands/bidi/models.ts b/lib/commands/bidi/models.ts index 17dcf0690..11073c6b7 100644 --- a/lib/commands/bidi/models.ts +++ b/lib/commands/bidi/models.ts @@ -1,7 +1,8 @@ -import type { LogEntryAddedEvent, ContextUpdatedEvent } from './types'; +import type { LogEntryAddedEvent, ContextUpdatedEvent, BiDiLogLevel } from './types'; import { NATIVE_WIN } from '../../utils'; import { CONTEXT_UPDATED_EVENT, CONTEXT_UPDATED_EVENT_OBSOLETE, LOG_ENTRY_ADDED_EVENT } from './constants'; import type { LogEntry } from '../types'; +import _ from 'lodash'; function toContextUpdatedEvent(method: string, contextName: string): ContextUpdatedEvent { return { @@ -30,7 +31,7 @@ export function makeLogEntryAddedEvent(entry: LogEntry, context: string, type: s method: LOG_ENTRY_ADDED_EVENT, params: { type, - level: entry.level, + level: adjustLogLevel(entry.level), source: { realm: '', }, @@ -39,3 +40,16 @@ export function makeLogEntryAddedEvent(entry: LogEntry, context: string, type: s }, }; } + +function adjustLogLevel(originalLevel: string): BiDiLogLevel { + const originalLevelLc = _.toLower(originalLevel); + switch (originalLevelLc) { + case 'debug': + case 'info': + case 'warn': + case 'error': + return originalLevelLc as BiDiLogLevel; + default: + return 'info'; + } +} diff --git a/lib/commands/bidi/types.ts b/lib/commands/bidi/types.ts index e19e00f42..f81241dbf 100644 --- a/lib/commands/bidi/types.ts +++ b/lib/commands/bidi/types.ts @@ -7,9 +7,11 @@ interface LogEntrySource { realm: string; } +export type BiDiLogLevel = 'debug' | 'info' | 'warn' | 'error'; + interface LogEntryAddedEventParams { type: string; - level: string; + level: BiDiLogLevel; source: LogEntrySource; text: string; timestamp: number;