Skip to content

Commit

Permalink
fix: Adjust log level for BiDi events (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Dec 19, 2024
1 parent 530b23d commit 3a4e264
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,11 +1,12 @@
import type { LogEntryAddedEvent, ContextUpdatedEvent } from './types';
import type { BiDiLogLevel, LogEntryAddedEvent, ContextUpdatedEvent } from './types';
import { NATIVE_WIN } from '../context/helpers';
import {
CONTEXT_UPDATED_EVENT,
LOG_ENTRY_ADDED_EVENT,
CONTEXT_UPDATED_EVENT_OBSOLETE,
} from './constants';
import type { LogcatRecord as LogEntry } from 'appium-adb';
import _ from 'lodash';

function toContextUpdatedEvent(method: string, contextName: string): ContextUpdatedEvent {
return {
Expand Down Expand Up @@ -34,7 +35,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 @@ -43,3 +44,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 3a4e264

Please sign in to comment.