fix(docutils): fix the docutils logger
Proxy wasn't working properly. Now it is
MODIFY
packages/docutils/lib/cli/index.ts
packages/docutils/lib/cli/index.ts
#!/usr/bin/env node
+import logger from '../logger';
-import {LogLevel} from 'consola';
import _ from 'lodash';
import {hideBin} from 'yargs/helpers';
import yargs from 'yargs/yargs';
-import {build, init, validate} from './command';
+import {DEFAULT_LOG_LEVEL, LogLevelMap, NAME_BIN} from '../constants';
import {DocutilsError} from '../error';
-import log from '../logger';
-import {DEFAULT_LOG_LEVEL, NAME_BIN} from '../constants';
-
-const LogLevelName = {
- silent: LogLevel.Silent,
- error: LogLevel.Error,
- warn: LogLevel.Warn,
- info: LogLevel.Info,
- debug: LogLevel.Debug,
-} as const;
+import {build, init, validate} from './command';
import {findConfig} from './config';
+const log = logger.withTag('cli');
export async function main(argv = hideBin(process.argv)) {
const config = await findConfig(argv);
@@ -29,16 +21,15 @@ export async function main(argv = hideBin(process.argv)) {
.command(validate)
.options({
verbose: {
- alias: 'V',
type: 'boolean',
describe: 'Alias for --log-level=debug',
},
'log-level': {
alias: 'L',
choices: ['debug', 'info', 'warn', 'error', 'silent'],
- default: DEFAULT_LOG_LEVEL,
describe: 'Sets the log level',
- coerce: _.identity as (x: string) => keyof typeof LogLevelName,
+ default: DEFAULT_LOG_LEVEL,
+ coerce: _.identity as (x: string) => keyof typeof LogLevelMap,
},
config: {
alias: 'c',
@@ -59,12 +50,11 @@ export async function main(argv = hideBin(process.argv)) {
* Configures logging; `--verbose` implies `--log-level=debug`
*/
(argv) => {
- const {logLevel, verbose} = argv;
- if (verbose) {
+ if (argv.verbose) {
argv.logLevel = 'debug';
log.debug('Debug logging enabled via --verbose');
}
- log.level = LogLevelName[logLevel];
+ log.level = LogLevelMap[argv.logLevel];
}
)
.fail(

MODIFY
packages/docutils/lib/constants.ts
packages/docutils/lib/constants.ts
* @module
*/
+import {LogLevel} from 'consola';
import {readFileSync} from 'node:fs';
import {fs} from '@appium/support';
import path from 'node:path';
@@ -107,3 +108,14 @@ export const REQUIREMENTS_TXT_PATH = path.join(PKG_ROOT_DIR, NAME_REQUIREMENTS_T
* The default output path for Typedoc, computed relative to the consuming package's root
*/
export const DEFAULT_REL_TYPEDOC_OUT_PATH = path.join('docs', 'reference');
+
+/**
+ * Mapping of `@appium/docutils`' log levels to `consola` log levels
+ */
+export const LogLevelMap = {
+ silent: LogLevel.Silent,
+ error: LogLevel.Error,
+ warn: LogLevel.Warn,
+ info: LogLevel.Info,
+ debug: LogLevel.Debug,
+} as const;

MODIFY
packages/docutils/lib/logger.ts
packages/docutils/lib/logger.ts
import consola from 'consola';
import type {Consola, ConsolaOptions, LogLevel} from 'consola';
-import {DEFAULT_LOG_LEVEL} from './constants';
+import {DEFAULT_LOG_LEVEL, LogLevelMap} from './constants';
/**
- * The logger from which all loggers are created
+ * The global log level
*
- * `withTag`/`withScope` is a way to namespace logs. This is more useful if using log objects, but
- * you can also see the scope when using the CLI app (if your terminal window is 80+ cols).
+ * "Global" inasmuch as any logger created from the root logger will use this level.
*/
-const rootLogger = consola.withTag('appium:docutils');
+let globalLevel = LogLevelMap[DEFAULT_LOG_LEVEL];
/**
- * The global log level
+ * The logger from which all loggers are created
*
- * "Global" inasmuch as any logger created from the root logger will use this level.
+ * `withTag`/`withScope` is a way to namespace logs. This is more useful if using log objects, but
+ * you can also see the scope when using the CLI app (if your terminal window is 80+ cols).
*/
-let globalLevel = rootLogger.level ?? DEFAULT_LOG_LEVEL;
+const rootLogger = createLogProxy(consola.withTag('docutils'));
/**
* @summary Creates a log-level-propagating proxy for a {@linkcode Consola} logger.
@@ -42,16 +42,20 @@ let globalLevel = rootLogger.level ?? DEFAULT_LOG_LEVEL;
*
* There are other ways to go about this which may be better, but this seemed pretty straightforward.
*/
-function createLogProxy(logger: Consola) {
+function createLogProxy(logger: Consola): Consola {
return new Proxy(logger, {
get(target, prop, receiver) {
if (prop === 'level') {
- return globalLevel ?? Reflect.get(target, prop, receiver);
+ return globalLevel;
}
if (prop === 'create') {
const create = Reflect.get(target, prop, receiver) as Consola['create'];
return (opts: ConsolaOptions) => createLogProxy(create.call(receiver, opts));
}
+ if (prop === '_defaults') {
+ const defaults = Reflect.get(target, prop, receiver);
+ return {...defaults, level: globalLevel};
+ }
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
@@ -68,4 +72,4 @@ function createLogProxy(logger: Consola) {
* The proxied root logger
* @see {createLogProxy}
*/
-export default createLogProxy(rootLogger);
+export default rootLogger;

fix(docutils): fix the docutils logger

Proxy wasn't working properly. Now it is