Skip to content

Commit

Permalink
fix: Adjust log level for BiDi events (#2505)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 19, 2024
1 parent aa4ad6d commit 1a73fcd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/commands/bidi/models.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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: '',
},
Expand All @@ -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';
}
}
4 changes: 3 additions & 1 deletion lib/commands/bidi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a73fcd

Please sign in to comment.