@storm-stack/cli
Advanced tools
Comparing version 1.13.10 to 1.13.11
@@ -6,4 +6,6 @@ /// <reference types="node" /> | ||
import { Fonts } from 'figlet'; | ||
import type { Logger } from 'pino'; | ||
import type { LoggerOptions } from 'pino'; | ||
import { Options } from 'figlet'; | ||
import pino from 'pino'; | ||
import type pino from 'pino'; | ||
import { Readable } from 'node:stream'; | ||
@@ -13,3 +15,3 @@ import { StdioOptions } from 'child_process'; | ||
import { Temporal } from '@js-temporal/polyfill'; | ||
import * as z from 'zod'; | ||
import type * as z from 'zod'; | ||
@@ -429,2 +431,10 @@ declare interface CLIArgument { | ||
stopwatch: (name?: string, startTime?: StormTime) => MaybePromise<void>; | ||
/** | ||
* Create a child logger | ||
* | ||
* @param name - The name of the child logger | ||
* @returns The child logger | ||
*/ | ||
child: (options: { name: string } & Record<string, any>) => IStormLog; | ||
} | ||
@@ -491,3 +501,3 @@ | ||
DEBUG: 60 as LogLevel, | ||
TRACE: 70 as LogLevel | ||
TRACE: 70 as LogLevel, | ||
}; | ||
@@ -511,3 +521,3 @@ | ||
DEBUG: "debug" as LogLevelLabel, | ||
TRACE: "trace" as LogLevelLabel | ||
TRACE: "trace" as LogLevelLabel, | ||
}; | ||
@@ -1302,3 +1312,3 @@ | ||
declare class StormLog implements IStormLog { | ||
private static logger: pino.BaseLogger; | ||
private static logger: Logger<LoggerOptions>; | ||
private static logLevel: LogLevel; | ||
@@ -1309,8 +1319,8 @@ private static logLevelLabel: LogLevelLabel; | ||
if (!StormLog.logger) { | ||
let config = await createStormConfig<"logging", LoggingConfig>( | ||
const config = await createStormConfig<"logging", LoggingConfig>( | ||
"logging", | ||
LoggingConfigSchema | ||
LoggingConfigSchema, | ||
); | ||
StormLog.logger = StormLog.initialize( | ||
config as StormConfig<"logging", LoggingConfig> | ||
config as StormConfig<"logging", LoggingConfig>, | ||
); | ||
@@ -1324,3 +1334,3 @@ StormLog.logLevel = getLogLevel(config.logLevel); | ||
logLevel: StormLog.logLevel, | ||
logLevelLabel: StormLog.logLevelLabel | ||
logLevelLabel: StormLog.logLevelLabel, | ||
}; | ||
@@ -1338,5 +1348,5 @@ }; | ||
config: StormConfig<"logging", LoggingConfig>, | ||
name?: string | ||
): pino.BaseLogger => { | ||
const pinoLogger: pino.BaseLogger = getPinoLogger(config, name); | ||
name?: string, | ||
): Logger<LoggerOptions> => { | ||
const pinoLogger: Logger<LoggerOptions> = getPinoLogger(config, name); | ||
pinoLogger.debug("The Storm log has ben initialized"); | ||
@@ -1347,9 +1357,9 @@ | ||
private _config: StormConfig<"logging", LoggingConfig>; | ||
private _name: string; | ||
private _logger: pino.BaseLogger; | ||
private _additionalLoggers: ILoggerWrapper[]; | ||
private _logLevel: LogLevel; | ||
private _logLevelLabel: LogLevelLabel; | ||
private _processes: Array<{ name: string; startedAt: StormTime }> = []; | ||
#config: StormConfig<"logging", LoggingConfig>; | ||
#name: string; | ||
#logger: Logger<LoggerOptions>; | ||
#additionalLoggers: ILoggerWrapper[]; | ||
#logLevel: LogLevel; | ||
#logLevelLabel: LogLevelLabel; | ||
#processes: Array<{ name: string; startedAt: StormTime }> = []; | ||
@@ -1363,14 +1373,14 @@ /** | ||
name?: string, | ||
additionalLoggers: ILoggerWrapper[] = [] | ||
additionalLoggers: ILoggerWrapper[] = [], | ||
) { | ||
const logger = StormLog.initialize(config, name); | ||
this.#config = config; | ||
this.#name = name ? name : config.name; | ||
this._config = config; | ||
this._name = name ? name : config.name; | ||
const logger = StormLog.initialize(this.#config, this.#name); | ||
this._logger = logger; | ||
this._additionalLoggers = additionalLoggers; | ||
this.#logger = logger; | ||
this.#additionalLoggers = additionalLoggers; | ||
this._logLevel = getLogLevel(config.logLevel); | ||
this._logLevelLabel = config.logLevel; | ||
this.#logLevel = getLogLevel(config.logLevel); | ||
this.#logLevelLabel = config.logLevel; | ||
} | ||
@@ -1389,3 +1399,3 @@ | ||
name?: string, | ||
additionalLoggers: ILoggerWrapper[] = [] | ||
additionalLoggers: ILoggerWrapper[] = [], | ||
) { | ||
@@ -1402,3 +1412,3 @@ return new StormLog(config, name, additionalLoggers); | ||
public static success(message: any) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.INFO && | ||
@@ -1418,3 +1428,3 @@ logger.info({ msg: message, level: "success" }); | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.FATAL && | ||
@@ -1434,3 +1444,3 @@ logger.fatal({ error, level: "fatal" }); | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.ERROR && | ||
@@ -1450,3 +1460,3 @@ logger.error({ error, level: "error" }); | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.ERROR && | ||
@@ -1464,3 +1474,3 @@ logger.error({ error, level: "exception" }); | ||
public static warn(message: any) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.WARN && logger.warn(message); | ||
@@ -1477,3 +1487,3 @@ }); | ||
public static info(message: any) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.INFO && logger.info(message); | ||
@@ -1490,3 +1500,3 @@ }); | ||
public static debug(message: any) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.DEBUG && logger.debug(message); | ||
@@ -1503,3 +1513,3 @@ }); | ||
public static trace(message: any) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.TRACE && logger.trace(message); | ||
@@ -1516,3 +1526,3 @@ }); | ||
public static log(message: any) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.INFO && logger.info(message); | ||
@@ -1528,8 +1538,8 @@ }); | ||
public static stopwatch(startTime: StormTime, name?: string) { | ||
this.getLoggers().then(logger => { | ||
StormLog.getLoggers().then((logger) => { | ||
StormLog.logLevel >= LogLevel.INFO && | ||
logger.info( | ||
`⏱️ The${name ? ` ${name}` : ""} process took ${formatSince( | ||
startTime.since() | ||
)} to complete` | ||
startTime.since(), | ||
)} to complete`, | ||
); | ||
@@ -1546,6 +1556,6 @@ }); | ||
public success(message: any) { | ||
if (this._logLevel >= LogLevel.INFO) { | ||
this._logger.info({ msg: message, level: "success" }); | ||
if (this.#logLevel >= LogLevel.INFO) { | ||
this.#logger.info({ msg: message, level: "success" }); | ||
Promise.all( | ||
this._additionalLoggers.map(logger => logger.success(message)) | ||
this.#additionalLoggers.map((logger) => logger.success(message)), | ||
); | ||
@@ -1562,7 +1572,7 @@ } | ||
public fatal(message: any) { | ||
if (this._logLevel >= LogLevel.FATAL) { | ||
if (this.#logLevel >= LogLevel.FATAL) { | ||
const error = getCauseFromUnknown(message); | ||
this._logger.fatal({ error, level: "fatal" }); | ||
Promise.all(this._additionalLoggers.map(logger => logger.fatal(error))); | ||
this.#logger.fatal({ error, level: "fatal" }); | ||
Promise.all(this.#additionalLoggers.map((logger) => logger.fatal(error))); | ||
} | ||
@@ -1578,7 +1588,7 @@ } | ||
public error(message: any) { | ||
if (this._logLevel >= LogLevel.ERROR) { | ||
if (this.#logLevel >= LogLevel.ERROR) { | ||
const error = getCauseFromUnknown(message); | ||
this._logger.error({ error, level: "error" }); | ||
Promise.all(this._additionalLoggers.map(logger => logger.error(error))); | ||
this.#logger.error({ error, level: "error" }); | ||
Promise.all(this.#additionalLoggers.map((logger) => logger.error(error))); | ||
} | ||
@@ -1594,8 +1604,8 @@ } | ||
public exception(message: any) { | ||
if (this._logLevel >= LogLevel.ERROR) { | ||
if (this.#logLevel >= LogLevel.ERROR) { | ||
const error = getCauseFromUnknown(message); | ||
this._logger.error({ error, level: "exception" }); | ||
this.#logger.error({ error, level: "exception" }); | ||
Promise.all( | ||
this._additionalLoggers.map(logger => logger.exception(error)) | ||
this.#additionalLoggers.map((logger) => logger.exception(error)), | ||
); | ||
@@ -1612,5 +1622,7 @@ } | ||
public warn(message: any) { | ||
if (this._logLevel >= LogLevel.WARN) { | ||
this._logger.warn(message); | ||
Promise.all(this._additionalLoggers.map(logger => logger.warn(message))); | ||
if (this.#logLevel >= LogLevel.WARN) { | ||
this.#logger.warn(message); | ||
Promise.all( | ||
this.#additionalLoggers.map((logger) => logger.warn(message)), | ||
); | ||
} | ||
@@ -1626,5 +1638,7 @@ } | ||
public info(message: any) { | ||
if (this._logLevel >= LogLevel.INFO) { | ||
this._logger.info(message); | ||
Promise.all(this._additionalLoggers.map(logger => logger.info(message))); | ||
if (this.#logLevel >= LogLevel.INFO) { | ||
this.#logger.info(message); | ||
Promise.all( | ||
this.#additionalLoggers.map((logger) => logger.info(message)), | ||
); | ||
} | ||
@@ -1640,5 +1654,7 @@ } | ||
public debug(message: any) { | ||
if (this._logLevel >= LogLevel.DEBUG) { | ||
this._logger.debug(message); | ||
Promise.all(this._additionalLoggers.map(logger => logger.debug(message))); | ||
if (this.#logLevel >= LogLevel.DEBUG) { | ||
this.#logger.debug(message); | ||
Promise.all( | ||
this.#additionalLoggers.map((logger) => logger.debug(message)), | ||
); | ||
} | ||
@@ -1654,5 +1670,7 @@ } | ||
public trace(message: any) { | ||
if (this._logLevel >= LogLevel.TRACE) { | ||
this._logger.trace(message); | ||
Promise.all(this._additionalLoggers.map(logger => logger.trace(message))); | ||
if (this.#logLevel >= LogLevel.TRACE) { | ||
this.#logger.trace(message); | ||
Promise.all( | ||
this.#additionalLoggers.map((logger) => logger.trace(message)), | ||
); | ||
} | ||
@@ -1668,5 +1686,5 @@ } | ||
public log(message: any) { | ||
if (this._logLevel >= LogLevel.INFO) { | ||
this._logger.info(message); | ||
Promise.all(this._additionalLoggers.map(logger => logger.log(message))); | ||
if (this.#logLevel >= LogLevel.INFO) { | ||
this.#logger.info(message); | ||
Promise.all(this.#additionalLoggers.map((logger) => logger.log(message))); | ||
} | ||
@@ -1681,5 +1699,5 @@ } | ||
public start(name: string) { | ||
if (this._logLevel >= LogLevel.INFO) { | ||
this._processes.push({ name, startedAt: StormTime.current() }); | ||
this._logger.info(`▶️ Starting process: ${this._processes.join(" > ")}`); | ||
if (this.#logLevel >= LogLevel.INFO) { | ||
this.#processes.push({ name, startedAt: StormTime.current() }); | ||
this.#logger.info(`▶️ Starting process: ${this.#processes.join(" ❯ ")}`); | ||
} | ||
@@ -1695,18 +1713,21 @@ } | ||
public stopwatch(name?: string, startTime?: StormTime) { | ||
if (this._logLevel < LogLevel.INFO) { | ||
let _startTime = startTime; | ||
if (this.#logLevel < LogLevel.INFO) { | ||
return; | ||
} | ||
if (!name && !startTime) { | ||
if (!name && !_startTime) { | ||
this.warn("No name or start time was provided to the stopwatch method"); | ||
return; | ||
} | ||
if (!startTime && !this._processes.some(item => item.name === name)) { | ||
if (!_startTime && !this.#processes.some((item) => item.name === name)) { | ||
this.warn( | ||
`No start time was provided and the ${name} process was never started` | ||
`No start time was provided and the ${name} process was never started`, | ||
); | ||
return; | ||
} | ||
if (name && this._processes.some(item => item.name === name)) { | ||
startTime = this._processes.find(item => item.name === name)?.startedAt; | ||
if (name && this.#processes.some((item) => item.name === name)) { | ||
_startTime = this.#processes.find( | ||
(item) => item.name === name, | ||
)?.startedAt; | ||
} | ||
@@ -1716,10 +1737,11 @@ | ||
if ( | ||
this._processes.length > 0 && | ||
this.#processes.length > 0 && | ||
process && | ||
this._processes.some(item => item.name === process) | ||
this.#processes.some((item) => item.name === process) | ||
) { | ||
process = this._processes | ||
process = this.#processes | ||
.map((item) => item.name) | ||
.slice( | ||
0, | ||
this._processes.findIndex(item => item.name === process) | ||
this.#processes.findIndex((item) => item.name === process), | ||
) | ||
@@ -1731,11 +1753,11 @@ .join(" > "); | ||
process ? `Completed process: ${process}` : "The process has completed" | ||
} \n\n⏱️ Process took ${formatSince(startTime!.since())} to complete`; | ||
} \n\n⏱️ Process took ${_startTime ? formatSince(_startTime.since()) : "0ms"} to complete`; | ||
this._logger.info(message); | ||
Promise.all(this._additionalLoggers.map(logger => logger.info(message))); | ||
this.#logger.info(message); | ||
Promise.all(this.#additionalLoggers.map((logger) => logger.info(message))); | ||
if (name && this._processes.some(item => item.name === name)) { | ||
const index = this._processes.findLastIndex(item => item.name === name); | ||
if (name && this.#processes.some((item) => item.name === name)) { | ||
const index = this.#processes.findLastIndex((item) => item.name === name); | ||
if (index) { | ||
this._processes.splice(index, 1); | ||
this.#processes.splice(index, 1); | ||
} | ||
@@ -1746,2 +1768,15 @@ } | ||
/** | ||
* Start a process | ||
* | ||
* @param options - The options of the child process | ||
*/ | ||
public child(options: { name: string } & Record<string, any>): IStormLog { | ||
return new StormLog( | ||
this.#config, | ||
`${this.#name} ❯ ${options?.name}`, | ||
this.#additionalLoggers, | ||
); | ||
} | ||
/** | ||
* Add a logger wrapper to the internal loggers list | ||
@@ -1753,3 +1788,3 @@ * | ||
if (wrapper) { | ||
this._additionalLoggers.push(wrapper); | ||
this.#additionalLoggers.push(wrapper); | ||
} | ||
@@ -1766,3 +1801,3 @@ } | ||
this.addWrappedLogger( | ||
LoggerWrapper.wrap(logger, this._config.modules!.logging) | ||
LoggerWrapper.wrap(logger, this.#config.modules?.logging), | ||
); | ||
@@ -1769,0 +1804,0 @@ } |
{ | ||
"name": "@storm-stack/cli", | ||
"version": "1.13.10", | ||
"version": "1.13.11", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "A collection of CLI utilities to assist in creating command line applications.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
331629
1736