vona-core 5.0.81 → 5.0.83

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.
@@ -72,8 +72,8 @@ export class VonaApplication extends KoaApplication {
72
72
  protocol: 'http',
73
73
  secure: 'false',
74
74
  method: 'POST',
75
- url: '/',
76
- path: '/',
75
+ url: '',
76
+ path: '',
77
77
  socket: {
78
78
  remoteAddress: '127.0.0.1',
79
79
  remotePort: 7001,
@@ -13,8 +13,8 @@ export declare class AppLogger extends BeanSimple {
13
13
  setLevel(level: LoggerLevel | boolean, clientName?: keyof ILoggerClientRecord): void;
14
14
  private _createClient;
15
15
  private _prepareConfigClient;
16
- makeTransportFile(clientInfo: ILoggerOptionsClientInfo, fileName: string, levelStrict?: LoggerLevel): DailyRotateFile | Winston.transports.FileTransportInstance;
16
+ makeTransportFile(clientInfo: ILoggerOptionsClientInfo, fileName: string, levelStrict?: LoggerLevel): DailyRotateFile | Winston.transports.FileTransportInstance | undefined;
17
17
  makeTransportConsole(clientInfo: ILoggerOptionsClientInfo): Transport | undefined;
18
- createTransportFile(fileName: string, clientInfo: ILoggerOptionsClientInfo, options: Winston.transports.FileTransportOptions | DailyRotateFile.DailyRotateFileTransportOptions): DailyRotateFile | Winston.transports.FileTransportInstance;
18
+ createTransportFile(fileName: string, clientInfo: ILoggerOptionsClientInfo, options: Winston.transports.FileTransportOptions | DailyRotateFile.DailyRotateFileTransportOptions): DailyRotateFile | Winston.transports.FileTransportInstance | undefined;
19
19
  }
20
20
  export {};
@@ -1,3 +1,4 @@
1
+ import fse from 'fs-extra';
1
2
  import * as Winston from 'winston';
2
3
  import DailyRotateFile from 'winston-daily-rotate-file';
3
4
  import { BeanSimple } from "../../bean/beanSimple.js";
@@ -75,6 +76,11 @@ export class AppLogger extends BeanSimple {
75
76
  });
76
77
  }
77
78
  createTransportFile(fileName, clientInfo, options) {
79
+ const dirname = this.app.config.server.loggerDir;
80
+ if (!fse.existsSync(dirname)) {
81
+ console.error(`========== Logger dir not exists: ${dirname} ==========`);
82
+ return;
83
+ }
78
84
  const configRotate = this.app.config.logger.rotate;
79
85
  let optionsFile;
80
86
  if (configRotate.enable) {
@@ -83,7 +89,7 @@ export class AppLogger extends BeanSimple {
83
89
  else {
84
90
  optionsFile = { filename: `${fileName}.log` };
85
91
  }
86
- const _options = deepExtend({ dirname: this.app.config.server.loggerDir }, optionsFile, options);
92
+ const _options = deepExtend({ dirname }, optionsFile, options);
87
93
  if (configRotate.enable) {
88
94
  const transport = new DailyRotateFile(_options);
89
95
  transport.on('error', err => {
@@ -1,5 +1,5 @@
1
1
  import { replaceTemplate } from '@cabloy/utils';
2
- import { formatLoggerAxiosError } from "./utils.js";
2
+ import { formatLoggerAxiosError, formatLoggerCtx } from "./utils.js";
3
3
  export function combineLoggerDefault(_appInfo, env) {
4
4
  const configDefault = {
5
5
  rotate: {
@@ -15,7 +15,7 @@ export function combineLoggerDefault(_appInfo, env) {
15
15
  },
16
16
  default(_clientInfo, { format }) {
17
17
  return {
18
- format: format.combine(formatLoggerAxiosError({ stack: true }), format.errors({ stack: true }), format.splat(), format.timestamp()),
18
+ format: format.combine(formatLoggerAxiosError({ stack: true }), formatLoggerCtx(), format.errors({ stack: true }), format.splat(), format.timestamp()),
19
19
  transports: undefined,
20
20
  };
21
21
  },
@@ -1,4 +1,5 @@
1
1
  import * as Winston from 'winston';
2
2
  export declare const formatLoggerAxiosError: Winston.Logform.FormatWrap;
3
+ export declare const formatLoggerCtx: Winston.Logform.FormatWrap;
3
4
  export declare const formatLoggerFilter: Winston.Logform.FormatWrap;
4
5
  export declare const formatLoggerConsole: () => Winston.Logform.Format;
@@ -1,6 +1,7 @@
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';
4
5
  import * as Winston from 'winston';
5
6
  import { cast } from "../../../types/utils/cast.js";
6
7
  const SymbolLoggerMessage = Symbol('SymbolLoggerMessage');
@@ -25,6 +26,14 @@ export const formatLoggerAxiosError = Winston.format((einfo, { stack, cause }) =
25
26
  }
26
27
  return einfo;
27
28
  });
29
+ export const formatLoggerCtx = Winston.format((info, _opts) => {
30
+ const app = useApp();
31
+ if (!app.ctx || !app.ctx.method || !app.ctx.path)
32
+ return info;
33
+ info.method = app.ctx.method;
34
+ info.path = app.ctx.path;
35
+ return info;
36
+ });
28
37
  export const formatLoggerFilter = Winston.format((info, opts) => {
29
38
  const level = typeof opts.level === 'function' ? opts.level() : opts.level;
30
39
  if (!level)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-core",
3
3
  "type": "module",
4
- "version": "5.0.81",
4
+ "version": "5.0.83",
5
5
  "description": "vona",
6
6
  "publishConfig": {
7
7
  "access": "public"