refactor(env): centralize app environment detection
This commit is contained in:
+6
-6
@@ -1,22 +1,22 @@
|
||||
import pino, { type Logger as PinoLogger, type LoggerOptions } from "pino";
|
||||
|
||||
import { isProduction, isTest } from "./app-env";
|
||||
import { AppEnvUtil } from "./app-env";
|
||||
|
||||
/**
|
||||
* 全局 pino root logger(单例,进程级复用)。
|
||||
*
|
||||
* 配置驱动(基于 `app-env.ts` 的 `isProduction()` / `isTest()`):
|
||||
* - production: info 级别 + JSON(机器可解析,接入日志平台)
|
||||
* 配置驱动(基于 `app-env.ts` 的 `AppEnvUtil`):
|
||||
* - production: silent(不输出日志)
|
||||
* - test: warn 级别(减少 vitest 噪音)
|
||||
* - development: debug 级别 + ISO 时间戳(人眼友好)
|
||||
*/
|
||||
const rootLogger: PinoLogger = pino(createLoggerOptions());
|
||||
|
||||
function createLoggerOptions(): LoggerOptions {
|
||||
if (isProduction()) {
|
||||
return { level: "info" };
|
||||
if (!AppEnvUtil.canOutputLogs()) {
|
||||
return { level: "silent" };
|
||||
}
|
||||
if (isTest()) {
|
||||
if (AppEnvUtil.isTest()) {
|
||||
return { level: "warn" };
|
||||
}
|
||||
// development
|
||||
|
||||
Reference in New Issue
Block a user