From 70d9367fd8cefccd14aca2f44ae46eb7967a2471 Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Tue, 29 Jun 2021 01:08:33 +0800 Subject: [PATCH] feat: add more logs to url --- src/services/libs/log/index.ts | 91 ++++++++++++++++++---------------- src/services/libs/url.ts | 8 ++- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/services/libs/log/index.ts b/src/services/libs/log/index.ts index 1f321e0f..173fd387 100644 --- a/src/services/libs/log/index.ts +++ b/src/services/libs/log/index.ts @@ -5,48 +5,51 @@ import 'winston-daily-rotate-file'; export * from './wikiOutput'; -const logger = (process.env.NODE_ENV === 'test' - ? Object.assign(console, { - emerg: console.error.bind(console), - alert: console.error.bind(console), - crit: console.error.bind(console), - warning: console.warn.bind(console), - notice: console.log.bind(console), - debug: console.log.bind(console), - }) - : winston.createLogger({ - levels: { - emerg: 0, - alert: 1, - crit: 2, - error: 3, - warning: 4, - warn: 5, - notice: 6, - info: 7, - debug: 8, - }, - transports: [ - new winston.transports.Console(), - new winston.transports.DailyRotateFile({ - filename: 'TiddlyGit-%DATE%.log', - datePattern: 'YYYY-MM-DD', - zippedArchive: false, - maxSize: '20mb', - maxFiles: '14d', - dirname: LOG_FOLDER, - }), - new RendererTransport(), - ], - exceptionHandlers: [ - new winston.transports.DailyRotateFile({ - filename: 'TiddlyGit-Exception-%DATE%.log', - datePattern: 'YYYY-MM-DD', - zippedArchive: false, - maxSize: '20mb', - maxFiles: '14d', - dirname: LOG_FOLDER, - }), - ], - })) as winston.Logger; +const logger = ( + process.env.NODE_ENV === 'test' + ? Object.assign(console, { + emerg: console.error.bind(console), + alert: console.error.bind(console), + crit: console.error.bind(console), + warning: console.warn.bind(console), + notice: console.log.bind(console), + debug: console.log.bind(console), + }) + : winston.createLogger({ + levels: { + emerg: 0, + alert: 1, + crit: 2, + error: 3, + warning: 4, + warn: 5, + notice: 6, + info: 7, + debug: 8, + }, + transports: [ + new winston.transports.Console(), + new winston.transports.DailyRotateFile({ + filename: 'TiddlyGit-%DATE%.log', + datePattern: 'YYYY-MM-DD', + zippedArchive: false, + maxSize: '20mb', + maxFiles: '14d', + dirname: LOG_FOLDER, + level: 'info', + }), + new RendererTransport(), + ], + exceptionHandlers: [ + new winston.transports.DailyRotateFile({ + filename: 'TiddlyGit-Exception-%DATE%.log', + datePattern: 'YYYY-MM-DD', + zippedArchive: false, + maxSize: '20mb', + maxFiles: '14d', + dirname: LOG_FOLDER, + }), + ], + }) +) as winston.Logger; export { logger }; diff --git a/src/services/libs/url.ts b/src/services/libs/url.ts index 7c9b0511..b9c39de8 100644 --- a/src/services/libs/url.ts +++ b/src/services/libs/url.ts @@ -1,5 +1,6 @@ import { networkInterfaces } from 'os'; import { defaultServerIP } from '@/constants/urls'; +import { logger } from './log'; const nets = networkInterfaces(); /** @@ -34,5 +35,10 @@ export function getAvailableIPAddress(): string | undefined { * @param originalUrl might be `"http://0.0.0.0:5212/"` */ export function getLocalHostUrlWithActualIP(originalUrl: string): string { - return originalUrl.replace(defaultServerIP, getAvailableIPAddress() ?? defaultServerIP); + const localHostUrlWithActualIP = originalUrl.replace(defaultServerIP, getAvailableIPAddress() ?? defaultServerIP); + logger.debug( + `Current available address: ${JSON.stringify(ipAddresses, undefined, ' ')}\nand getAvailableIPAddress() returns ${getAvailableIPAddress() ?? 'undefined'} + originalUrl: ${originalUrl} , localHostUrlWithActualIP ${localHostUrlWithActualIP}`, + ); + return localHostUrlWithActualIP; }