Skip to content

Commit

Permalink
fix: Update logs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark authored and KotRikD committed Dec 9, 2024
1 parent 2536925 commit 9a42746
Show file tree
Hide file tree
Showing 35 changed files with 1,281 additions and 1,004 deletions.
9 changes: 6 additions & 3 deletions packages/common/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export const updateConfigFile = () => {
}

if (newOptions !== '') {
wLogger.warn(`New options available in config: ${newOptions}\n`);
wLogger.warn(
'[config]',
`New options available in config: ${newOptions}\n`
);
}
};

Expand Down Expand Up @@ -200,7 +203,7 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {

const { parsed, error } = dotenv.config({ path: configPath });
if (error != null || parsed == null) {
wLogger.error(`Config ${status} failed`);
wLogger.error('[config]', `Config ${status} failed`);
return;
}

Expand Down Expand Up @@ -295,7 +298,7 @@ export const refreshConfig = (httpServer: any, refresh: boolean) => {
fs.mkdirSync(staticPath);
}

if (updated) wLogger.info(`Config ${status}ed`);
if (updated) wLogger.info('[config]', `Config ${status}ed`);
};

export const writeConfig = (httpServer: any, options: any) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/common/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ export const wLogger = {
const coloredText = colorText('info');
console.log(coloredText, ...args);

if (config.debugLogging === true) writeLog('info', args);
writeLog('info', args);
},
debug: (...args: any) => {
writeLog('debug', args);

if (config.debugLogging !== true) return;

const coloredText = colorText('debug');
console.log(coloredText, ...args);

writeLog('debug', args);
},
debugError: (...args: any) => {
if (config.debugLogging !== true) return;

const coloredText = colorText('debugError');
console.log(coloredText, ...args);

if (config.debugLogging === true) writeLog('debugError', args);
writeLog('debugError', args);
},
error: (...args: any) => {
const coloredText = colorText('error');
console.log(coloredText, ...args);

if (config.debugLogging === true) writeLog('error', args);
writeLog('error', args);
},
warn: (...args: any) => {
const coloredText = colorText('warn');
console.log(coloredText, ...args);

if (config.debugLogging === true) writeLog('warn', args);
writeLog('warn', args);
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/common/utils/unzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const unzip = (zipPath: string, extractPath: string): Promise<string> =>
zip.extractAllTo(extractPath, /* overwrite */ true);
resolve(extractPath);
} catch (error) {
wLogger.error((error as any).message);
wLogger.debug(error);
wLogger.error('[unzip]', (error as any).message);
wLogger.debug('[unzip]', error);
reject(error);
}
});
2 changes: 1 addition & 1 deletion packages/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Server {
return next();
}

wLogger.warn('Unallowed request', req.url, {
wLogger.warn('[request]', 'Unallowed request', req.url, {
address: req.socket.remoteAddress,
origin: req.headers.origin,
referer: req.headers.referer
Expand Down
6 changes: 2 additions & 4 deletions packages/server/router/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ export default function buildAssetsApi(server: Server) {
path.join(pkgAssetsPath, req.params.filePath),
(err, content) => {
if (err) {
wLogger.debug(err);
res.writeHead(404, {
'Content-Type': 'text/html'
});
wLogger.debug(`/assets/${req.params.filePath}`, err);
res.writeHead(404, { 'Content-Type': 'text/html' });

res.end('<html>page not found</html>');
return;
Expand Down
Loading

0 comments on commit 9a42746

Please sign in to comment.