vona-core 5.0.79 → 5.0.81

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.
@@ -1,5 +1,5 @@
1
1
  import type winston from 'winston';
2
- import type { ILoggerClientChildRecord } from '../../types/interface/logger.ts';
2
+ import type { ILoggerChildRecord, ILoggerClientRecord } from '../../types/interface/logger.ts';
3
3
  import type { IModuleLocaleText } from './resource/locale/type.ts';
4
4
  import type { IBeanScopeContainer } from './scope/beanScopeContainer.ts';
5
5
  import { BeanBaseSimple } from './beanBaseSimple.ts';
@@ -12,7 +12,8 @@ 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 $loggerChild(childName: keyof ILoggerClientChildRecord): winston.Logger;
15
+ protected $loggerClient(clientName: keyof ILoggerClientRecord): winston.Logger;
16
+ protected $loggerChild(childName: keyof ILoggerChildRecord, clientName?: keyof ILoggerClientRecord): winston.Logger;
16
17
  protected get $scope(): IBeanScopeContainer;
17
18
  get scope(): unknown;
18
19
  }
@@ -4,7 +4,7 @@ const SymbolLogger = Symbol('SymbolLogger');
4
4
  const SymbolLoggerChildren = Symbol('SymbolLoggerChildren');
5
5
  export class BeanBase extends BeanBaseSimple {
6
6
  [SymbolText];
7
- [SymbolLogger];
7
+ [SymbolLogger] = {};
8
8
  [SymbolLoggerChildren] = {};
9
9
  get $text() {
10
10
  if (!this[SymbolText]) {
@@ -13,19 +13,24 @@ export class BeanBase extends BeanBaseSimple {
13
13
  return this[SymbolText];
14
14
  }
15
15
  get $logger() {
16
- if (!this[SymbolLogger]) {
17
- this[SymbolLogger] = this.app.meta.logger.get().child({ beanFullName: this.$beanFullName });
16
+ return this.$loggerClient('default');
17
+ }
18
+ $loggerClient(clientName) {
19
+ if (!this[SymbolLogger][clientName]) {
20
+ this[SymbolLogger][clientName] = this.app.meta.logger.get(clientName).child({ beanFullName: this.$beanFullName });
18
21
  }
19
- return this[SymbolLogger];
22
+ return this[SymbolLogger][clientName];
20
23
  }
21
- $loggerChild(childName) {
22
- if (!this[SymbolLoggerChildren][childName]) {
23
- this[SymbolLoggerChildren][childName] = this.app.meta.logger.get().child({
24
+ $loggerChild(childName, clientName = 'default') {
25
+ if (!this[SymbolLoggerChildren][clientName])
26
+ this[SymbolLoggerChildren][clientName] = {};
27
+ if (!this[SymbolLoggerChildren][clientName][childName]) {
28
+ this[SymbolLoggerChildren][clientName][childName] = this.app.meta.logger.get(clientName).child({
24
29
  beanFullName: this.$beanFullName,
25
30
  name: childName,
26
31
  });
27
32
  }
28
- return this[SymbolLoggerChildren][childName];
33
+ return this[SymbolLoggerChildren][clientName][childName];
29
34
  }
30
35
  get $scope() {
31
36
  return this.app.meta.scopeContainer;
@@ -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("./beanContainer.ts").BeanContainer;
6
+ protected get bean(): import("vona").BeanContainer;
7
7
  }
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import fse from 'fs-extra';
4
4
  import { cast } from "../../types/utils/cast.js";
5
5
  import { deepExtend } from "../utils/util.js";
6
- import { combineLoggerDefault } from "./loggerDefault.js";
6
+ import { combineLoggerDefault } from "./logger/loggerDefault.js";
7
7
  export function combineAppConfigDefault(appInfo, env) {
8
8
  let config = configDefault(appInfo, env);
9
9
  const mode = appInfo.configMeta.mode;
@@ -1,22 +1,20 @@
1
- import type { ILoggerClientChildRecord, ILoggerClientRecord, ILoggerOptionsClientInfo, LoggerLevel } from '../../types/interface/logger.ts';
1
+ import type * as Transport from 'winston-transport';
2
+ import type { ILoggerChildRecord, ILoggerClientRecord, ILoggerOptionsClientInfo, LoggerLevel } from '../../../types/interface/logger.ts';
2
3
  import * as Winston from 'winston';
3
4
  import DailyRotateFile from 'winston-daily-rotate-file';
4
- import { BeanSimple } from '../bean/beanSimple.ts';
5
+ import { BeanSimple } from '../../bean/beanSimple.ts';
5
6
  declare const SymbolLoggerInstances: unique symbol;
6
7
  export declare class AppLogger extends BeanSimple {
7
8
  private [SymbolLoggerInstances];
8
9
  dispose(): Promise<void>;
9
10
  get(clientName?: keyof ILoggerClientRecord): Winston.Logger;
10
- child(childName?: keyof ILoggerClientChildRecord, clientName?: keyof ILoggerClientRecord): Winston.Logger;
11
+ child(childName?: keyof ILoggerChildRecord, clientName?: keyof ILoggerClientRecord): Winston.Logger;
11
12
  getLevel(clientName?: keyof ILoggerClientRecord): LoggerLevel | undefined;
12
13
  setLevel(level: LoggerLevel | boolean, clientName?: keyof ILoggerClientRecord): void;
13
14
  private _createClient;
14
15
  private _prepareConfigClient;
16
+ makeTransportFile(clientInfo: ILoggerOptionsClientInfo, fileName: string, levelStrict?: LoggerLevel): DailyRotateFile | Winston.transports.FileTransportInstance;
17
+ makeTransportConsole(clientInfo: ILoggerOptionsClientInfo): Transport | undefined;
15
18
  createTransportFile(fileName: string, clientInfo: ILoggerOptionsClientInfo, options: Winston.transports.FileTransportOptions | DailyRotateFile.DailyRotateFileTransportOptions): DailyRotateFile | Winston.transports.FileTransportInstance;
16
19
  }
17
- export declare function getLoggerClientLevel(clientName?: keyof ILoggerClientRecord): LoggerLevel | undefined;
18
- export declare function setLoggerClientLevel(level: LoggerLevel | boolean, clientName?: keyof ILoggerClientRecord): void;
19
- export declare const formatLoggerAxiosError: Winston.Logform.FormatWrap;
20
- export declare const formatLoggerFilter: Winston.Logform.FormatWrap;
21
- export declare const formatLoggerConsole: () => Winston.Logform.Format;
22
20
  export {};
@@ -0,0 +1,108 @@
1
+ import * as Winston from 'winston';
2
+ import DailyRotateFile from 'winston-daily-rotate-file';
3
+ import { BeanSimple } from "../../bean/beanSimple.js";
4
+ import { deepExtend } from "../../utils/util.js";
5
+ import { formatLoggerConsole, formatLoggerFilter } from "./utils.js";
6
+ const SymbolLoggerInstances = Symbol('SymbolLoggerInstances');
7
+ export class AppLogger extends BeanSimple {
8
+ [SymbolLoggerInstances] = {};
9
+ async dispose() {
10
+ for (const key in this[SymbolLoggerInstances]) {
11
+ const logger = this[SymbolLoggerInstances][key];
12
+ await _closeLogger(logger);
13
+ }
14
+ }
15
+ get(clientName) {
16
+ clientName = clientName || 'default';
17
+ if (!this[SymbolLoggerInstances][clientName]) {
18
+ this[SymbolLoggerInstances][clientName] = this._createClient(clientName);
19
+ }
20
+ return this[SymbolLoggerInstances][clientName];
21
+ }
22
+ child(childName, clientName) {
23
+ const logger = this.get(clientName);
24
+ if (!childName)
25
+ return logger;
26
+ return logger.child({ name: childName });
27
+ }
28
+ getLevel(clientName) {
29
+ clientName = clientName || 'default';
30
+ const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
31
+ const level = this.app.meta.env[envName];
32
+ if (level === 'false')
33
+ return;
34
+ if (level === 'true' || !level)
35
+ return 'info';
36
+ return level;
37
+ }
38
+ setLevel(level, clientName) {
39
+ clientName = clientName || 'default';
40
+ const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
41
+ this.app.meta.env[envName] = level.toString();
42
+ }
43
+ _createClient(clientName) {
44
+ const configClient = this.app.config.logger.clients[clientName];
45
+ if (!configClient)
46
+ throw new Error(`logger client not found: ${clientName}`);
47
+ const configNode = deepExtend({}, this._prepareConfigClient(clientName, this.app.config.logger.default), this._prepareConfigClient(clientName, configClient));
48
+ const logger = Winston.createLogger(configNode);
49
+ logger.on('error', err => {
50
+ console.error(err);
51
+ });
52
+ return logger;
53
+ }
54
+ _prepareConfigClient(clientName, configClient) {
55
+ if (typeof configClient !== 'function')
56
+ return configClient;
57
+ return configClient.call(this.app, {
58
+ clientName,
59
+ level: () => this.getLevel(clientName),
60
+ }, Winston);
61
+ }
62
+ makeTransportFile(clientInfo, fileName, levelStrict) {
63
+ return this.createTransportFile(fileName, clientInfo, {
64
+ level: levelStrict ?? 'silly',
65
+ format: Winston.format.combine(formatLoggerFilter({ level: levelStrict ?? clientInfo.level, strict: !!levelStrict }), Winston.format.json()),
66
+ });
67
+ }
68
+ makeTransportConsole(clientInfo) {
69
+ if (this.app.meta.env.LOGGER_DUMMY === 'true')
70
+ return;
71
+ return new Winston.transports.Console({
72
+ level: 'silly',
73
+ format: Winston.format.combine(formatLoggerFilter({ level: clientInfo.level, silly: true }), Winston.format.colorize(), formatLoggerConsole()),
74
+ forceConsole: true,
75
+ });
76
+ }
77
+ createTransportFile(fileName, clientInfo, options) {
78
+ const configRotate = this.app.config.logger.rotate;
79
+ let optionsFile;
80
+ if (configRotate.enable) {
81
+ optionsFile = configRotate.options.call(this, fileName, Winston, clientInfo);
82
+ }
83
+ else {
84
+ optionsFile = { filename: `${fileName}.log` };
85
+ }
86
+ const _options = deepExtend({ dirname: this.app.config.server.loggerDir }, optionsFile, options);
87
+ if (configRotate.enable) {
88
+ const transport = new DailyRotateFile(_options);
89
+ transport.on('error', err => {
90
+ console.error(err);
91
+ });
92
+ return transport;
93
+ }
94
+ else {
95
+ return new Winston.transports.File(_options);
96
+ }
97
+ }
98
+ }
99
+ async function _closeLogger(logger) {
100
+ return new Promise(resolve => {
101
+ if (logger.__closed__)
102
+ return resolve(true);
103
+ logger.end(() => {
104
+ logger.__closed__ = true;
105
+ resolve(true);
106
+ });
107
+ });
108
+ }
@@ -0,0 +1,3 @@
1
+ export * from './appLogger.ts';
2
+ export * from './loggerDefault.ts';
3
+ export * from './utils.ts';
@@ -0,0 +1,3 @@
1
+ export * from "./appLogger.js";
2
+ export * from "./loggerDefault.js";
3
+ export * from "./utils.js";
@@ -0,0 +1,5 @@
1
+ import type { PowerPartial } from 'vona';
2
+ import type { VonaAppInfo } from '../../../types/application/app.ts';
3
+ import type { ConfigLogger } from '../../../types/interface/logger.ts';
4
+ import type { VonaConfigEnv } from '../../../types/utils/env.ts';
5
+ export declare function combineLoggerDefault(_appInfo: VonaAppInfo, env: VonaConfigEnv): PowerPartial<ConfigLogger>;
@@ -0,0 +1,36 @@
1
+ import { replaceTemplate } from '@cabloy/utils';
2
+ import { formatLoggerAxiosError } from "./utils.js";
3
+ export function combineLoggerDefault(_appInfo, env) {
4
+ const configDefault = {
5
+ rotate: {
6
+ enable: env.LOGGER_ROTATE_ENABLE === 'true',
7
+ options(filename) {
8
+ return {
9
+ filename: replaceTemplate(env.LOGGER_ROTATE_FILENAME, { filename }),
10
+ datePattern: env.LOGGER_ROTATE_DATEPATTERN,
11
+ maxSize: env.LOGGER_ROTATE_MAXSIZE,
12
+ maxFiles: env.LOGGER_ROTATE_MAXFILES,
13
+ };
14
+ },
15
+ },
16
+ default(_clientInfo, { format }) {
17
+ return {
18
+ format: format.combine(formatLoggerAxiosError({ stack: true }), format.errors({ stack: true }), format.splat(), format.timestamp()),
19
+ transports: undefined,
20
+ };
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
+ },
34
+ };
35
+ return configDefault;
36
+ }
@@ -0,0 +1,4 @@
1
+ import * as Winston from 'winston';
2
+ export declare const formatLoggerAxiosError: Winston.Logform.FormatWrap;
3
+ export declare const formatLoggerFilter: Winston.Logform.FormatWrap;
4
+ export declare const formatLoggerConsole: () => Winston.Logform.Format;
@@ -0,0 +1,60 @@
1
+ import { isEmptyObject } from '@cabloy/utils';
2
+ import chalk from 'chalk';
3
+ import { LEVEL, MESSAGE } from 'triple-beam';
4
+ import * as Winston from 'winston';
5
+ import { cast } from "../../../types/utils/cast.js";
6
+ const SymbolLoggerMessage = Symbol('SymbolLoggerMessage');
7
+ export const formatLoggerAxiosError = Winston.format((einfo, { stack, cause }) => {
8
+ if ((einfo instanceof Error && einfo.constructor.name.includes('AxiosError')) || einfo.name === 'AxiosError') {
9
+ const info = Object.assign({}, einfo, {
10
+ level: einfo.level,
11
+ [LEVEL]: einfo[LEVEL] || einfo.level,
12
+ message: einfo.message,
13
+ [MESSAGE]: einfo[MESSAGE] || einfo.message,
14
+ });
15
+ if (stack)
16
+ info.stack = einfo.stack;
17
+ if (cause)
18
+ info.cause = einfo.cause;
19
+ info.message = `${info.message}: ${cast(info.config).url}`;
20
+ info[MESSAGE] = `${info[MESSAGE]}: ${cast(info.config).url}`;
21
+ delete info.config;
22
+ delete info.request;
23
+ delete info.response;
24
+ return info;
25
+ }
26
+ return einfo;
27
+ });
28
+ export const formatLoggerFilter = Winston.format((info, opts) => {
29
+ const level = typeof opts.level === 'function' ? opts.level() : opts.level;
30
+ if (!level)
31
+ return false;
32
+ if (opts.strict) {
33
+ if (Winston.config.npm.levels[info.level] === Winston.config.npm.levels[level])
34
+ return __formatLoggerFilterCheckInfo(info);
35
+ return false;
36
+ }
37
+ if (Winston.config.npm.levels[info.level] <= Winston.config.npm.levels[level] || (opts.silly && info.level === 'silly'))
38
+ return __formatLoggerFilterCheckInfo(info);
39
+ return false;
40
+ });
41
+ export const formatLoggerConsole = () => {
42
+ return Winston.format.printf(({ timestamp, level, stack, message, name, beanFullName, durationMs, ...meta }) => {
43
+ const textName = name ? ` ${chalk.cyan(`[${name}]`)}` : '';
44
+ const textBeanFullName = beanFullName ? ` ${chalk.gray(`[${beanFullName}]`)}` : '';
45
+ const textMeta = !isEmptyObject(meta) ? ` ${JSON.stringify(meta)}` : '';
46
+ const textMessage = ` ${message}`;
47
+ const textDurationMs = durationMs !== undefined ? ` ${chalk.cyan(`+${durationMs}ms`)}` : '';
48
+ const textStack = stack ? `\n${stack}` : '';
49
+ return `${timestamp} ${level}${textName}${textBeanFullName}${textMeta}${textMessage}${textDurationMs}${textStack}`;
50
+ });
51
+ };
52
+ function __formatLoggerFilterCheckInfo(info) {
53
+ if (typeof info.message === 'function') {
54
+ if (info.message[SymbolLoggerMessage] === undefined) {
55
+ info.message[SymbolLoggerMessage] = info.message();
56
+ }
57
+ info.message = info.message[SymbolLoggerMessage];
58
+ }
59
+ return info;
60
+ }
@@ -7,7 +7,7 @@ import type { AppResource } from './resource.ts';
7
7
  import { BeanSimple } from '../bean/beanSimple.ts';
8
8
  import { AppLocale, BeanScopeContainer } from '../bean/index.ts';
9
9
  import { CtxCounter } from './ctxCounter.ts';
10
- import { AppLogger } from './logger.ts';
10
+ import { AppLogger } from './logger/appLogger.ts';
11
11
  export declare class AppMeta extends BeanSimple {
12
12
  env: VonaConfigEnv;
13
13
  ctxCounter: CtxCounter;
@@ -3,7 +3,7 @@ import { EnumAppEvent } from "../../types/index.js";
3
3
  import { BeanSimple } from "../bean/beanSimple.js";
4
4
  import { AppLocale, BeanScopeContainer } from "../bean/index.js";
5
5
  import { CtxCounter } from "./ctxCounter.js";
6
- import { AppLogger } from "./logger.js";
6
+ import { AppLogger } from "./logger/appLogger.js";
7
7
  import { appMetadata } from "./metadata.js";
8
8
  import { appResource } from "./resource.js";
9
9
  const SymbolClosePromise = Symbol('SymbolClosePromise');
@@ -4,12 +4,12 @@ export interface ILoggerOptionsClientInfo {
4
4
  clientName: keyof ILoggerClientRecord;
5
5
  level: () => (LoggerLevel | undefined);
6
6
  }
7
- export type TypeLoggerOptions = Winston.LoggerOptions | ((winston: typeof Winston, clientInfo: ILoggerOptionsClientInfo) => Winston.LoggerOptions);
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;
9
9
  export interface ILoggerClientRecord {
10
10
  default: never;
11
11
  }
12
- export interface ILoggerClientChildRecord {
12
+ export interface ILoggerChildRecord {
13
13
  }
14
14
  export interface ConfigLogger {
15
15
  default: TypeLoggerOptions;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-core",
3
3
  "type": "module",
4
- "version": "5.0.79",
4
+ "version": "5.0.81",
5
5
  "description": "vona",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -29,10 +29,10 @@
29
29
  "@cabloy/extend": "^3.1.10",
30
30
  "@cabloy/json5": "^1.0.18",
31
31
  "@cabloy/localeutil": "^2.0.10",
32
- "@cabloy/module-info": "^1.3.30",
33
- "@cabloy/module-info-pro": "^1.0.38",
32
+ "@cabloy/module-info": "^1.3.31",
33
+ "@cabloy/module-info-pro": "^1.0.39",
34
34
  "@cabloy/set": "^1.0.17",
35
- "@cabloy/utils": "^1.0.45",
35
+ "@cabloy/utils": "^1.0.46",
36
36
  "@cabloy/word-utils": "^2.0.1",
37
37
  "@cabloy/zod-errors-custom": "^2.0.3",
38
38
  "@cabloy/zod-openapi": "^1.0.3",
@@ -47,6 +47,7 @@
47
47
  "uuid": "^11.0.3",
48
48
  "winston": "^3.18.3",
49
49
  "winston-daily-rotate-file": "^5.0.0",
50
+ "winston-transport": "^4.9.0",
50
51
  "zod": "^4.1.5"
51
52
  },
52
53
  "gitHead": "0eab9dc4a5622caffe89e7b1b3f02c08ccbc4c4b",
@@ -1,157 +0,0 @@
1
- import { isEmptyObject } from '@cabloy/utils';
2
- import chalk from 'chalk';
3
- import { LEVEL, MESSAGE } from 'triple-beam';
4
- import * as Winston from 'winston';
5
- import DailyRotateFile from 'winston-daily-rotate-file';
6
- import { cast } from "../../types/utils/cast.js";
7
- import { BeanSimple } from "../bean/beanSimple.js";
8
- import { deepExtend } from "../utils/util.js";
9
- const SymbolLoggerInstances = Symbol('SymbolLoggerInstances');
10
- const SymbolLoggerMessage = Symbol('SymbolLoggerMessage');
11
- export class AppLogger extends BeanSimple {
12
- [SymbolLoggerInstances] = {};
13
- async dispose() {
14
- for (const key in this[SymbolLoggerInstances]) {
15
- const logger = this[SymbolLoggerInstances][key];
16
- await _closeLogger(logger);
17
- }
18
- }
19
- get(clientName) {
20
- clientName = clientName || 'default';
21
- if (!this[SymbolLoggerInstances][clientName]) {
22
- this[SymbolLoggerInstances][clientName] = this._createClient(clientName);
23
- }
24
- return this[SymbolLoggerInstances][clientName];
25
- }
26
- child(childName, clientName) {
27
- const logger = this.get(clientName);
28
- if (!childName)
29
- return logger;
30
- return logger.child({ name: childName });
31
- }
32
- getLevel(clientName) {
33
- return getLoggerClientLevel(clientName);
34
- }
35
- setLevel(level, clientName) {
36
- setLoggerClientLevel(level, clientName);
37
- }
38
- _createClient(clientName) {
39
- const configClient = this.app.config.logger.clients[clientName];
40
- if (!configClient)
41
- throw new Error(`logger client not found: ${clientName}`);
42
- const configNode = deepExtend({}, this._prepareConfigClient(clientName, this.app.config.logger.default), this._prepareConfigClient(clientName, configClient));
43
- const logger = Winston.createLogger(configNode);
44
- logger.on('error', err => {
45
- console.error(err);
46
- });
47
- return logger;
48
- }
49
- _prepareConfigClient(clientName, configClient) {
50
- if (typeof configClient !== 'function')
51
- return configClient;
52
- return configClient.call(this.app, Winston, {
53
- clientName,
54
- level: () => getLoggerClientLevel(clientName),
55
- });
56
- }
57
- createTransportFile(fileName, clientInfo, options) {
58
- const configRotate = this.app.config.logger.rotate;
59
- let optionsFile;
60
- if (configRotate.enable) {
61
- optionsFile = configRotate.options.call(this, fileName, Winston, clientInfo);
62
- }
63
- else {
64
- optionsFile = { filename: `${fileName}.log` };
65
- }
66
- const _options = deepExtend({ dirname: this.app.config.server.loggerDir }, optionsFile, options);
67
- if (configRotate.enable) {
68
- const transport = new DailyRotateFile(_options);
69
- transport.on('error', err => {
70
- console.error(err);
71
- });
72
- return transport;
73
- }
74
- else {
75
- return new Winston.transports.File(_options);
76
- }
77
- }
78
- }
79
- async function _closeLogger(logger) {
80
- return new Promise(resolve => {
81
- if (logger.__closed__)
82
- return resolve(true);
83
- logger.end(() => {
84
- logger.__closed__ = true;
85
- resolve(true);
86
- });
87
- });
88
- }
89
- export function getLoggerClientLevel(clientName) {
90
- clientName = clientName || 'default';
91
- const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
92
- const level = process.env[envName];
93
- if (level === 'false')
94
- return;
95
- if (level === 'true' || !level)
96
- return 'info';
97
- return level;
98
- }
99
- export function setLoggerClientLevel(level, clientName) {
100
- clientName = clientName || 'default';
101
- const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
102
- process.env[envName] = level.toString();
103
- }
104
- export const formatLoggerAxiosError = Winston.format((einfo, { stack, cause }) => {
105
- if ((einfo instanceof Error && einfo.constructor.name.includes('AxiosError')) || einfo.name === 'AxiosError') {
106
- const info = Object.assign({}, einfo, {
107
- level: einfo.level,
108
- [LEVEL]: einfo[LEVEL] || einfo.level,
109
- message: einfo.message,
110
- [MESSAGE]: einfo[MESSAGE] || einfo.message,
111
- });
112
- if (stack)
113
- info.stack = einfo.stack;
114
- if (cause)
115
- info.cause = einfo.cause;
116
- info.message = `${info.message}: ${cast(info.config).url}`;
117
- info[MESSAGE] = `${info[MESSAGE]}: ${cast(info.config).url}`;
118
- delete info.config;
119
- delete info.request;
120
- delete info.response;
121
- return info;
122
- }
123
- return einfo;
124
- });
125
- export const formatLoggerFilter = Winston.format((info, opts) => {
126
- const level = typeof opts.level === 'function' ? opts.level() : opts.level;
127
- if (!level)
128
- return false;
129
- if (opts.strict) {
130
- if (Winston.config.npm.levels[info.level] === Winston.config.npm.levels[level])
131
- return __formatLoggerFilterCheckInfo(info);
132
- return false;
133
- }
134
- if (Winston.config.npm.levels[info.level] <= Winston.config.npm.levels[level] || (opts.silly && info.level === 'silly'))
135
- return __formatLoggerFilterCheckInfo(info);
136
- return false;
137
- });
138
- export const formatLoggerConsole = () => {
139
- return Winston.format.printf(({ timestamp, level, stack, message, name, beanFullName, durationMs, ...meta }) => {
140
- const textName = name ? ` ${chalk.cyan(`[${name}]`)}` : '';
141
- const textBeanFullName = beanFullName ? ` ${chalk.gray(`[${beanFullName}]`)}` : '';
142
- const textMeta = !isEmptyObject(meta) ? ` ${JSON.stringify(meta)}` : '';
143
- const textMessage = ` ${message}`;
144
- const textDurationMs = durationMs !== undefined ? ` ${chalk.cyan(`+${durationMs}ms`)}` : '';
145
- const textStack = stack ? `\n${stack}` : '';
146
- return `${timestamp} ${level}${textName}${textBeanFullName}${textMeta}${textMessage}${textDurationMs}${textStack}`;
147
- });
148
- };
149
- function __formatLoggerFilterCheckInfo(info) {
150
- if (typeof info.message === 'function') {
151
- if (info.message[SymbolLoggerMessage] === undefined) {
152
- info.message[SymbolLoggerMessage] = info.message();
153
- }
154
- info.message = info.message[SymbolLoggerMessage];
155
- }
156
- return info;
157
- }
@@ -1,4 +0,0 @@
1
- import type { VonaAppInfo } from '../../types/application/app.ts';
2
- import type { ConfigLogger } from '../../types/interface/logger.ts';
3
- import type { VonaConfigEnv } from '../../types/utils/env.ts';
4
- export declare function combineLoggerDefault(_appInfo: VonaAppInfo, env: VonaConfigEnv): ConfigLogger;
@@ -1,52 +0,0 @@
1
- import { replaceTemplate } from '@cabloy/utils';
2
- import { formatLoggerAxiosError, formatLoggerConsole, formatLoggerFilter } from "./logger.js";
3
- export function combineLoggerDefault(_appInfo, env) {
4
- const configDefault = {
5
- rotate: {
6
- enable: env.LOGGER_ROTATE_ENABLE === 'true',
7
- options(filename) {
8
- return {
9
- filename: replaceTemplate(env.LOGGER_ROTATE_FILENAME, { filename }),
10
- datePattern: env.LOGGER_ROTATE_DATEPATTERN,
11
- maxSize: env.LOGGER_ROTATE_MAXSIZE,
12
- maxFiles: env.LOGGER_ROTATE_MAXFILES,
13
- };
14
- },
15
- },
16
- default({ format, transports }, clientInfo) {
17
- const _transports = [
18
- this.meta.logger.createTransportFile('error', clientInfo, {
19
- level: 'error',
20
- format: format.combine(formatLoggerFilter({ level: 'error', strict: true }), format.json()),
21
- }),
22
- this.meta.logger.createTransportFile('warn', clientInfo, {
23
- level: 'warn',
24
- format: format.combine(formatLoggerFilter({ level: 'warn', strict: true }), format.json()),
25
- }),
26
- this.meta.logger.createTransportFile('http', clientInfo, {
27
- level: 'http',
28
- format: format.combine(formatLoggerFilter({ level: 'http', strict: true }), format.json()),
29
- }),
30
- this.meta.logger.createTransportFile('combined', clientInfo, {
31
- level: 'silly',
32
- format: format.combine(formatLoggerFilter({ level: clientInfo.level }), format.json()),
33
- }),
34
- ];
35
- if (env.LOGGER_DUMMY !== 'true') {
36
- _transports.push(new transports.Console({
37
- level: 'silly',
38
- format: format.combine(formatLoggerFilter({ level: clientInfo.level, silly: true }), format.colorize(), formatLoggerConsole()),
39
- forceConsole: true,
40
- }));
41
- }
42
- return {
43
- format: format.combine(formatLoggerAxiosError({ stack: true }), format.errors({ stack: true }), format.splat(), format.timestamp()),
44
- transports: _transports,
45
- };
46
- },
47
- clients: {
48
- default: {},
49
- },
50
- };
51
- return configDefault;
52
- }