mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(server/debug): Added initial implementation of new Logger (#84)
- Logs out to a file w/ relevant meta data - Provides better readability for end user This should help provide better troubleshooting for both development and end users. This also fixes any previous catches that were attempting to print stack traces, causing the [object Object] message to appear. Co-authored-by: Christopher Gjelten <[email protected]>
This commit is contained in:
1 parent
a5491302b6
commit
211576e237
18 files changed
+363
-114
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import winston from 'winston';
|
||||
import config from '../utils/config';
|
||||
import path from 'path';
|
||||
|
||||
// Needed to manually apply a color to componenent property of log
|
||||
const manualColorize = (strToColor: string): string =>
|
||||
`[\x1b[35m${strToColor}\x1b[0m]`;
|
||||
|
||||
// Format handler passed to winston
|
||||
const formatLogs = (log: winston.Logform.TransformableInfo): string => {
|
||||
if (log.module)
|
||||
return `${log.label} ${manualColorize(log.module)} [${log.level}]: ${
|
||||
log.message
|
||||
}`;
|
||||
|
||||
return `${log.label} [${log.level}]: ${log.message}`;
|
||||
};
|
||||
|
||||
const findLogPath = () =>
|
||||
`${path.join(GetResourcePath(GetCurrentResourceName()), 'sv_npwd.log')}`;
|
||||
// Initiate the main logger for NPWD
|
||||
|
||||
export const mainLogger = winston.createLogger({
|
||||
level: config.debug.level,
|
||||
transports: [
|
||||
new winston.transports.File({
|
||||
filename: findLogPath(),
|
||||
format: winston.format.combine(
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
),
|
||||
}),
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.label({ label: '[NPWD]' }),
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.printf(formatLogs)
|
||||
),
|
||||
}),
|
||||
],
|
||||
});
|
||||
Reference in new issue
Block a user