@ubean/shared 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/logger/hono.js
CHANGED
package/dist/logger/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { i as UbeanLoggerOptions, n as RequestLoggerOptions, r as UbeanLogger, t as LogLevelName } from "../types-CFy62PZV.js";
|
|
2
|
+
import { TLogLevel } from "tslog";
|
|
2
3
|
//#region src/logger/logger.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* 创建一个 ubean 命名的 tslog logger(默认 name 为 `ubean`)。
|
|
@@ -45,5 +46,22 @@ export declare function getLogger(scope?: string, options?: UbeanLoggerOptions):
|
|
|
45
46
|
* ```
|
|
46
47
|
*/
|
|
47
48
|
export declare function setDebugLogging(enabled: boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* 设置全局日志级别(对已创建与后续创建的所有 logger 实例生效)。
|
|
51
|
+
*
|
|
52
|
+
* 供 CLI 在加载 `logging.level` 配置后调用,覆盖 `LOG_LEVEL`/`TSLOG_LEVEL` 环境
|
|
53
|
+
* 变量的既有效果。传入 `undefined` 为空操作(不覆盖环境变量语义)。
|
|
54
|
+
*
|
|
55
|
+
* 注意:必须走 tslog 实例的 `setMinLevel()` 方法 —— 它会把级别名归一化为数字 id
|
|
56
|
+
* (`tslog` 内部用数值比较过滤);直接改写 `settings.minLevel` 字符串会让比较失真。
|
|
57
|
+
* tslog 的级别名解析大小写不敏感,这里统一大写仅为通过其类型签名。
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const config = await loadUbeanConfig(cwd);
|
|
62
|
+
* if (config.logging.level) setMinLevel(config.logging.level);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function setMinLevel(level: LogLevelName | TLogLevel | undefined): void;
|
|
48
66
|
//#endregion
|
|
49
67
|
export type { LogLevelName, RequestLoggerOptions, UbeanLogger, UbeanLoggerOptions };
|
package/dist/logger/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as setDebugLogging, n as getLogger, r as logger, t as createUbeanLogger } from "../logger-
|
|
2
|
-
export { createUbeanLogger, getLogger, logger, setDebugLogging };
|
|
1
|
+
import { a as setMinLevel, i as setDebugLogging, n as getLogger, r as logger, t as createUbeanLogger } from "../logger-NMOHjTCB.js";
|
|
2
|
+
export { createUbeanLogger, getLogger, logger, setDebugLogging, setMinLevel };
|
|
@@ -15,6 +15,11 @@ const DEBUG_PRETTY_TEMPLATE = "{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}} {{log
|
|
|
15
15
|
const DEFAULT_MIN_LEVEL = "INFO";
|
|
16
16
|
/** 是否处于 debug 模式(输出详细模板) */
|
|
17
17
|
let debugMode = false;
|
|
18
|
+
/**
|
|
19
|
+
* 配置文件显式指定的日志级别(`logging.level`,归一化为大写)。
|
|
20
|
+
* 优先级:logger 显式 `minLevel` > 此配置 > `LOG_LEVEL`/`TSLOG_LEVEL` 环境变量 > `info`。
|
|
21
|
+
*/
|
|
22
|
+
let configuredMinLevel;
|
|
18
23
|
/** 已创建的 logger 实例注册表,`setDebugLogging` 切换模板时统一更新(含子 logger) */
|
|
19
24
|
const instances = /* @__PURE__ */ new Set();
|
|
20
25
|
function registerInstance(instance) {
|
|
@@ -79,7 +84,7 @@ function getLogLevelFromEnv() {
|
|
|
79
84
|
* ```
|
|
80
85
|
*/
|
|
81
86
|
function createUbeanLogger(options = {}) {
|
|
82
|
-
const minLevel = options.minLevel ?? getLogLevelFromEnv() ?? DEFAULT_MIN_LEVEL;
|
|
87
|
+
const minLevel = options.minLevel ?? configuredMinLevel ?? getLogLevelFromEnv() ?? DEFAULT_MIN_LEVEL;
|
|
83
88
|
return registerInstance(new Logger({
|
|
84
89
|
name: DEFAULT_NAME,
|
|
85
90
|
...options,
|
|
@@ -130,5 +135,27 @@ function setDebugLogging(enabled) {
|
|
|
130
135
|
debugMode = enabled;
|
|
131
136
|
for (const instance of instances) applyDebugMode(instance);
|
|
132
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* 设置全局日志级别(对已创建与后续创建的所有 logger 实例生效)。
|
|
140
|
+
*
|
|
141
|
+
* 供 CLI 在加载 `logging.level` 配置后调用,覆盖 `LOG_LEVEL`/`TSLOG_LEVEL` 环境
|
|
142
|
+
* 变量的既有效果。传入 `undefined` 为空操作(不覆盖环境变量语义)。
|
|
143
|
+
*
|
|
144
|
+
* 注意:必须走 tslog 实例的 `setMinLevel()` 方法 —— 它会把级别名归一化为数字 id
|
|
145
|
+
* (`tslog` 内部用数值比较过滤);直接改写 `settings.minLevel` 字符串会让比较失真。
|
|
146
|
+
* tslog 的级别名解析大小写不敏感,这里统一大写仅为通过其类型签名。
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const config = await loadUbeanConfig(cwd);
|
|
151
|
+
* if (config.logging.level) setMinLevel(config.logging.level);
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function setMinLevel(level) {
|
|
155
|
+
if (!level || typeof level !== "string") return;
|
|
156
|
+
configuredMinLevel = level.toUpperCase();
|
|
157
|
+
const name = level.toUpperCase();
|
|
158
|
+
for (const instance of instances) instance.setMinLevel(name);
|
|
159
|
+
}
|
|
133
160
|
//#endregion
|
|
134
|
-
export { setDebugLogging as i, getLogger as n, logger as r, createUbeanLogger as t };
|
|
161
|
+
export { setMinLevel as a, setDebugLogging as i, getLogger as n, logger as r, createUbeanLogger as t };
|