vona-core 5.0.84 → 5.0.87
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/lib/bean/beanBase.d.ts +1 -1
- package/dist/lib/bean/beanBase.js +1 -1
- package/dist/lib/bean/beanSimple.d.ts +1 -1
- package/dist/lib/core/index.d.ts +1 -0
- package/dist/lib/core/index.js +1 -0
- package/dist/lib/core/logger/appLogger.d.ts +2 -5
- package/dist/lib/core/logger/appLogger.js +3 -20
- package/dist/lib/core/logger/loggerDefault.d.ts +1 -1
- package/dist/lib/core/logger/loggerDefault.js +2 -13
- package/dist/lib/core/logger/utils.d.ts +2 -1
- package/dist/lib/core/logger/utils.js +4 -3
- package/dist/lib/framework/process.js +10 -2
- package/dist/types/interface/logger.d.ts +7 -6
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ export declare class BeanBase extends BeanBaseSimple {
|
|
|
12
12
|
private [SymbolLoggerChildren];
|
|
13
13
|
protected get $text(): IModuleLocaleText;
|
|
14
14
|
protected get $logger(): winston.Logger;
|
|
15
|
-
protected $loggerClient(clientName
|
|
15
|
+
protected $loggerClient(clientName?: keyof ILoggerClientRecord): winston.Logger;
|
|
16
16
|
protected $loggerChild(childName: keyof ILoggerChildRecord, clientName?: keyof ILoggerClientRecord): winston.Logger;
|
|
17
17
|
protected get $scope(): IBeanScopeContainer;
|
|
18
18
|
get scope(): unknown;
|
|
@@ -15,7 +15,7 @@ export class BeanBase extends BeanBaseSimple {
|
|
|
15
15
|
get $logger() {
|
|
16
16
|
return this.$loggerClient('default');
|
|
17
17
|
}
|
|
18
|
-
$loggerClient(clientName) {
|
|
18
|
+
$loggerClient(clientName = 'default') {
|
|
19
19
|
if (!this[SymbolLogger][clientName]) {
|
|
20
20
|
this[SymbolLogger][clientName] = this.app.meta.logger.get(clientName).child({ beanFullName: this.$beanFullName });
|
|
21
21
|
}
|
|
@@ -3,5 +3,5 @@ import type { VonaApplication } from '../core/application.ts';
|
|
|
3
3
|
export declare class BeanSimple {
|
|
4
4
|
protected app: VonaApplication;
|
|
5
5
|
protected get ctx(): VonaContext;
|
|
6
|
-
protected get bean(): import("
|
|
6
|
+
protected get bean(): import("./beanContainer.ts").BeanContainer;
|
|
7
7
|
}
|
package/dist/lib/core/index.d.ts
CHANGED
package/dist/lib/core/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type * as Transport from 'winston-transport';
|
|
2
1
|
import type { ILoggerChildRecord, ILoggerClientRecord, ILoggerOptionsClientInfo, LoggerLevel } from '../../../types/interface/logger.ts';
|
|
3
2
|
import * as Winston from 'winston';
|
|
4
3
|
import DailyRotateFile from 'winston-daily-rotate-file';
|
|
@@ -9,12 +8,10 @@ export declare class AppLogger extends BeanSimple {
|
|
|
9
8
|
dispose(): Promise<void>;
|
|
10
9
|
get(clientName?: keyof ILoggerClientRecord): Winston.Logger;
|
|
11
10
|
child(childName?: keyof ILoggerChildRecord, clientName?: keyof ILoggerClientRecord): Winston.Logger;
|
|
12
|
-
getLevel(clientName?: keyof ILoggerClientRecord): LoggerLevel |
|
|
11
|
+
getLevel(clientName?: keyof ILoggerClientRecord): LoggerLevel | false;
|
|
13
12
|
setLevel(level: LoggerLevel | boolean, clientName?: keyof ILoggerClientRecord): void;
|
|
14
13
|
private _createClient;
|
|
15
14
|
private _prepareConfigClient;
|
|
16
|
-
|
|
17
|
-
makeTransportConsole(clientInfo: ILoggerOptionsClientInfo): Transport | undefined;
|
|
18
|
-
createTransportFile(fileName: string, clientInfo: ILoggerOptionsClientInfo, options: Winston.transports.FileTransportOptions | DailyRotateFile.DailyRotateFileTransportOptions): DailyRotateFile | Winston.transports.FileTransportInstance | undefined;
|
|
15
|
+
createTransportFile(fileName: string, clientInfo: ILoggerOptionsClientInfo, options: Winston.transports.FileTransportOptions | DailyRotateFile.DailyRotateFileTransportOptions): DailyRotateFile | Winston.transports.FileTransportInstance;
|
|
19
16
|
}
|
|
20
17
|
export {};
|
|
@@ -4,7 +4,6 @@ import * as Winston from 'winston';
|
|
|
4
4
|
import DailyRotateFile from 'winston-daily-rotate-file';
|
|
5
5
|
import { BeanSimple } from "../../bean/beanSimple.js";
|
|
6
6
|
import { deepExtend } from "../../utils/util.js";
|
|
7
|
-
import { formatLoggerConsole, formatLoggerFilter } from "./utils.js";
|
|
8
7
|
const SymbolLoggerInstances = Symbol('SymbolLoggerInstances');
|
|
9
8
|
export class AppLogger extends BeanSimple {
|
|
10
9
|
[SymbolLoggerInstances] = {};
|
|
@@ -32,7 +31,7 @@ export class AppLogger extends BeanSimple {
|
|
|
32
31
|
const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
|
|
33
32
|
const level = this.app.meta.env[envName];
|
|
34
33
|
if (level === 'false')
|
|
35
|
-
return;
|
|
34
|
+
return false;
|
|
36
35
|
if (level === 'true' || !level)
|
|
37
36
|
return 'info';
|
|
38
37
|
return level;
|
|
@@ -46,7 +45,7 @@ export class AppLogger extends BeanSimple {
|
|
|
46
45
|
const configClient = this.app.config.logger.clients[clientName];
|
|
47
46
|
if (!configClient)
|
|
48
47
|
throw new Error(`logger client not found: ${clientName}`);
|
|
49
|
-
const configNode = deepExtend({}, this._prepareConfigClient(clientName, this.app.config.logger.
|
|
48
|
+
const configNode = deepExtend({}, this._prepareConfigClient(clientName, this.app.config.logger.base), this._prepareConfigClient(clientName, configClient));
|
|
50
49
|
const logger = Winston.createLogger(configNode);
|
|
51
50
|
logger.on('error', err => {
|
|
52
51
|
console.error(err);
|
|
@@ -61,21 +60,6 @@ export class AppLogger extends BeanSimple {
|
|
|
61
60
|
level: () => this.getLevel(clientName),
|
|
62
61
|
}, Winston);
|
|
63
62
|
}
|
|
64
|
-
makeTransportFile(clientInfo, fileName, levelStrict) {
|
|
65
|
-
return this.createTransportFile(fileName, clientInfo, {
|
|
66
|
-
level: levelStrict ?? 'silly',
|
|
67
|
-
format: Winston.format.combine(formatLoggerFilter({ level: levelStrict ?? clientInfo.level, strict: !!levelStrict }), Winston.format.json()),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
makeTransportConsole(clientInfo) {
|
|
71
|
-
if (this.app.meta.env.LOGGER_DUMMY === 'true')
|
|
72
|
-
return;
|
|
73
|
-
return new Winston.transports.Console({
|
|
74
|
-
level: 'silly',
|
|
75
|
-
format: Winston.format.combine(formatLoggerFilter({ level: clientInfo.level, silly: true }), Winston.format.colorize(), formatLoggerConsole()),
|
|
76
|
-
forceConsole: true,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
63
|
createTransportFile(fileName, clientInfo, options) {
|
|
80
64
|
const dirname = this.app.config.server.loggerDir;
|
|
81
65
|
if (!fse.existsSync(dirname)) {
|
|
@@ -83,8 +67,7 @@ export class AppLogger extends BeanSimple {
|
|
|
83
67
|
fse.ensureDirSync(dirname);
|
|
84
68
|
});
|
|
85
69
|
if (err) {
|
|
86
|
-
|
|
87
|
-
return;
|
|
70
|
+
throw new Error(`Failed to create logger dir: ${dirname}`);
|
|
88
71
|
}
|
|
89
72
|
}
|
|
90
73
|
const configRotate = this.app.config.logger.rotate;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PowerPartial } from 'vona';
|
|
2
1
|
import type { VonaAppInfo } from '../../../types/application/app.ts';
|
|
3
2
|
import type { ConfigLogger } from '../../../types/interface/logger.ts';
|
|
4
3
|
import type { VonaConfigEnv } from '../../../types/utils/env.ts';
|
|
4
|
+
import type { PowerPartial } from '../../../types/utils/powerPartial.ts';
|
|
5
5
|
export declare function combineLoggerDefault(_appInfo: VonaAppInfo, env: VonaConfigEnv): PowerPartial<ConfigLogger>;
|
|
@@ -13,24 +13,13 @@ export function combineLoggerDefault(_appInfo, env) {
|
|
|
13
13
|
};
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
|
-
|
|
16
|
+
base(_clientInfo, { format }) {
|
|
17
17
|
return {
|
|
18
18
|
format: format.combine(formatLoggerAxiosError({ stack: true }), formatLoggerCtx(), format.errors({ stack: true }), format.splat(), format.timestamp()),
|
|
19
19
|
transports: undefined,
|
|
20
20
|
};
|
|
21
21
|
},
|
|
22
|
-
clients: {
|
|
23
|
-
default(clientInfo) {
|
|
24
|
-
const transports = [
|
|
25
|
-
this.meta.logger.makeTransportFile(clientInfo, 'error', 'error'),
|
|
26
|
-
this.meta.logger.makeTransportFile(clientInfo, 'warn', 'warn'),
|
|
27
|
-
this.meta.logger.makeTransportFile(clientInfo, 'http', 'http'),
|
|
28
|
-
this.meta.logger.makeTransportFile(clientInfo, 'combined'),
|
|
29
|
-
this.meta.logger.makeTransportConsole(clientInfo),
|
|
30
|
-
].filter(item => !!item);
|
|
31
|
-
return { transports };
|
|
32
|
-
},
|
|
33
|
-
},
|
|
22
|
+
clients: {},
|
|
34
23
|
};
|
|
35
24
|
return configDefault;
|
|
36
25
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ILoggerOptionsClientInfo } from '../../../types/interface/logger.ts';
|
|
1
2
|
import * as Winston from 'winston';
|
|
2
3
|
export declare const formatLoggerAxiosError: Winston.Logform.FormatWrap;
|
|
3
4
|
export declare const formatLoggerCtx: Winston.Logform.FormatWrap;
|
|
4
5
|
export declare const formatLoggerFilter: Winston.Logform.FormatWrap;
|
|
5
|
-
export declare const formatLoggerConsole: () => Winston.Logform.Format;
|
|
6
|
+
export declare const formatLoggerConsole: (clientInfo: ILoggerOptionsClientInfo) => Winston.Logform.Format;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isEmptyObject } from '@cabloy/utils';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { LEVEL, MESSAGE } from 'triple-beam';
|
|
4
|
-
import { useApp } from 'vona';
|
|
5
4
|
import * as Winston from 'winston';
|
|
6
5
|
import { cast } from "../../../types/utils/cast.js";
|
|
6
|
+
import { useApp } from "../../framework/useApp.js";
|
|
7
7
|
const SymbolLoggerMessage = Symbol('SymbolLoggerMessage');
|
|
8
8
|
export const formatLoggerAxiosError = Winston.format((einfo, { stack, cause }) => {
|
|
9
9
|
if ((einfo instanceof Error && einfo.constructor.name.includes('AxiosError')) || einfo.name === 'AxiosError') {
|
|
@@ -47,15 +47,16 @@ export const formatLoggerFilter = Winston.format((info, opts) => {
|
|
|
47
47
|
return __formatLoggerFilterCheckInfo(info);
|
|
48
48
|
return false;
|
|
49
49
|
});
|
|
50
|
-
export const formatLoggerConsole = () => {
|
|
50
|
+
export const formatLoggerConsole = (clientInfo) => {
|
|
51
51
|
return Winston.format.printf(({ timestamp, level, stack, message, name, beanFullName, durationMs, ...meta }) => {
|
|
52
|
+
const textClientName = clientInfo.clientName === 'default' ? '' : ` ${chalk.cyan(`[${clientInfo.clientName}]`)}`;
|
|
52
53
|
const textName = name ? ` ${chalk.cyan(`[${name}]`)}` : '';
|
|
53
54
|
const textBeanFullName = beanFullName ? ` ${chalk.gray(`[${beanFullName}]`)}` : '';
|
|
54
55
|
const textMeta = !isEmptyObject(meta) ? ` ${JSON.stringify(meta)}` : '';
|
|
55
56
|
const textMessage = ` ${message}`;
|
|
56
57
|
const textDurationMs = durationMs !== undefined ? ` ${chalk.cyan(`+${durationMs}ms`)}` : '';
|
|
57
58
|
const textStack = stack ? `\n${stack}` : '';
|
|
58
|
-
return `${timestamp} ${level}${textName}${textBeanFullName}${textMeta}${textMessage}${textDurationMs}${textStack}`;
|
|
59
|
+
return `${timestamp} ${level}${textClientName}${textName}${textBeanFullName}${textMeta}${textMessage}${textDurationMs}${textStack}`;
|
|
59
60
|
});
|
|
60
61
|
};
|
|
61
62
|
function __formatLoggerFilterCheckInfo(info) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { catchErrorSync } from '@cabloy/utils';
|
|
1
2
|
import { closeApp, useApp } from "./useApp.js";
|
|
2
3
|
export function handleProcessWork() {
|
|
3
4
|
process.once('SIGUSR2', async () => {
|
|
@@ -15,8 +16,15 @@ export function handleProcessWork() {
|
|
|
15
16
|
process.kill(process.pid, 'SIGTERM');
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
const logger =
|
|
19
|
-
|
|
19
|
+
const [logger] = catchErrorSync(() => {
|
|
20
|
+
return app.meta.logger.get();
|
|
21
|
+
});
|
|
22
|
+
if (logger) {
|
|
23
|
+
logger.error(err);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
console.error(err);
|
|
27
|
+
}
|
|
20
28
|
if (!app.meta.appStarted) {
|
|
21
29
|
await app.meta.logger.dispose();
|
|
22
30
|
process.kill(process.pid, 'SIGTERM');
|
|
@@ -2,7 +2,7 @@ import type * as Winston from 'winston';
|
|
|
2
2
|
import type DailyRotateFile from 'winston-daily-rotate-file';
|
|
3
3
|
export interface ILoggerOptionsClientInfo {
|
|
4
4
|
clientName: keyof ILoggerClientRecord;
|
|
5
|
-
level: () => (LoggerLevel |
|
|
5
|
+
level: () => (LoggerLevel | false);
|
|
6
6
|
}
|
|
7
7
|
export type TypeLoggerOptions = Winston.LoggerOptions | ((clientInfo: ILoggerOptionsClientInfo, winston: typeof Winston) => Winston.LoggerOptions);
|
|
8
8
|
export type TypeLoggerRotateOptions = (fileName: string, winston: typeof Winston, clientInfo: ILoggerOptionsClientInfo) => DailyRotateFile.DailyRotateFileTransportOptions;
|
|
@@ -11,13 +11,14 @@ export interface ILoggerClientRecord {
|
|
|
11
11
|
}
|
|
12
12
|
export interface ILoggerChildRecord {
|
|
13
13
|
}
|
|
14
|
+
export interface ILoggerRotateConfig {
|
|
15
|
+
enable: boolean;
|
|
16
|
+
options: TypeLoggerRotateOptions;
|
|
17
|
+
}
|
|
14
18
|
export interface ConfigLogger {
|
|
15
|
-
|
|
19
|
+
base: TypeLoggerOptions;
|
|
16
20
|
clients: Record<keyof ILoggerClientRecord, TypeLoggerOptions>;
|
|
17
|
-
rotate:
|
|
18
|
-
enable: boolean;
|
|
19
|
-
options: TypeLoggerRotateOptions;
|
|
20
|
-
};
|
|
21
|
+
rotate: ILoggerRotateConfig;
|
|
21
22
|
}
|
|
22
23
|
export type LoggerLevel = 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
|
|
23
24
|
declare module 'winston' {
|