feat(logger): Add the debug level to the default logger (#20219)

* feat(logger): Add the debug level to the default logger
This commit is contained in:
Kazuaki Matsuo
2024-06-07 09:43:49 -07:00
committed by GitHub
parent 1c19a8dbba
commit 8ee7d07af4
4 changed files with 22 additions and 4 deletions

View File

@@ -1,11 +1,10 @@
import globalLog from '@appium/logger';
import {createLogger, format, transports} from 'winston';
import {fs, logger} from '@appium/support';
import {fs} from '@appium/support';
import { APPIUM_LOGGER_NAME } from './logger';
import _ from 'lodash';
// set up distributed logging before everything else
logger.patchLogger(globalLog);
global._global_npmlog = globalLog;
// npmlog is used only for emitting, we use winston for output

View File

@@ -6,10 +6,12 @@ import consoleControl from 'console-control-strings';
import * as util from 'node:util';
import type {MessageObject, StyleObject, Logger, LogLevel} from './types';
import type {Writable} from 'node:stream';
import { unleakString } from './utils';
const DEFAULT_LOG_LEVELS: any[][] = [
['silly', -Infinity, {inverse: true}, 'sill'],
['verbose', 1000, {fg: 'cyan', bg: 'black'}, 'verb'],
['debug', 1500, {fg: 'cyan', bg: 'black'}, 'dbug'],
['info', 2000, {fg: 'green'}],
['timing', 2500, {fg: 'green', bg: 'black'}],
['http', 3000, {fg: 'green', bg: 'black'}],
@@ -114,6 +116,10 @@ export class Log extends EventEmitter implements Logger {
this.log('verbose', prefix, message, ...args);
}
debug(prefix: string, message: any, ...args: any[]): void {
this.log('debug', prefix, message, ...args);
}
info(prefix: string, message: any, ...args: any[]): void {
this.log('info', prefix, message, ...args);
}
@@ -190,8 +196,8 @@ export class Log extends EventEmitter implements Logger {
id: this._id++,
timestamp: Date.now(),
level,
prefix: String(prefix || ''),
message: formattedMessage,
prefix: unleakString(prefix || ''),
message: unleakString(formattedMessage),
};
this.emit('log', m);

View File

@@ -25,6 +25,7 @@ export interface Logger extends EventEmitter {
*/
silly(prefix: string, message: any, ...args: any[]): void;
verbose(prefix: string, message: any, ...args: any[]): void;
debug(prefix: string, message: any, ...args: any[]): void;
info(prefix: string, message: any, ...args: any[]): void;
timing(prefix: string, message: any, ...args: any[]): void;
http(prefix: string, message: any, ...args: any[]): void;
@@ -57,6 +58,7 @@ export interface Logger extends EventEmitter {
export type LogLevel =
| 'silly'
| 'verbose'
| 'debug'
| 'info'
| 'timing'
| 'http'

View File

@@ -0,0 +1,11 @@
/**
* This function is necessary to workaround unexpected memory leaks
* caused by NodeJS string interning
* behavior described in https://bugs.chromium.org/p/v8/issues/detail?id=2869
*
* @param {any} s - The string to unleak
* @return {string} Either the unleaked string or the original object converted to string
*/
export function unleakString(s: any): string {
return ` ${s}`.substring(1);
}