feat: add more logs to url

This commit is contained in:
tiddlygit-test 2021-06-29 01:08:33 +08:00
parent 0a3c0f4ac4
commit 70d9367fd8
2 changed files with 54 additions and 45 deletions

View file

@ -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 };

View file

@ -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;
}