mirror of
https://github.com/xxnuo/MTranServer.git
synced 2026-09-03 06:35:20 +08:00
feat: force output of service startup information
Introduced logger.important to allow logging specific messages regardless of the configured log level. Updated server startup to use logger.important for Service URL and Swagger Docs location, ensuring visibility even with default warn level.
This commit is contained in:
@@ -76,8 +76,8 @@ function getLogStream() {
|
||||
return logStream;
|
||||
}
|
||||
|
||||
function log(level: LogLevel, color: string, message: string, ...args: any[]) {
|
||||
if (!shouldLog(level)) return;
|
||||
function logInternal(level: LogLevel, color: string, force: boolean, message: string, ...args: any[]) {
|
||||
if (!force && !shouldLog(level)) return;
|
||||
|
||||
const timestamp = getTimestamp();
|
||||
const formattedMessage = util.format(message, ...args);
|
||||
@@ -102,6 +102,10 @@ function log(level: LogLevel, color: string, message: string, ...args: any[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function log(level: LogLevel, color: string, message: string, ...args: any[]) {
|
||||
logInternal(level, color, false, message, ...args);
|
||||
}
|
||||
|
||||
export function debug(message: string, ...args: any[]) {
|
||||
log('debug', colors.cyan, message, ...args);
|
||||
}
|
||||
@@ -110,6 +114,10 @@ export function info(message: string, ...args: any[]) {
|
||||
log('info', colors.green, message, ...args);
|
||||
}
|
||||
|
||||
export function important(message: string, ...args: any[]) {
|
||||
logInternal('info', colors.green, true, message, ...args);
|
||||
}
|
||||
|
||||
export function warn(message: string, ...args: any[]) {
|
||||
log('warn', colors.yellow, message, ...args);
|
||||
}
|
||||
@@ -128,6 +136,7 @@ export default {
|
||||
getLogLevel,
|
||||
debug,
|
||||
info,
|
||||
important,
|
||||
warn,
|
||||
error,
|
||||
fatal,
|
||||
|
||||
@@ -39,9 +39,9 @@ export async function run() {
|
||||
app.use(errorHandler());
|
||||
|
||||
const server = app.listen(parseInt(config.port), config.host, () => {
|
||||
logger.info(`HTTP Service URL: http://${config.host}:${config.port}`);
|
||||
logger.info(`Swagger Docs: http://${config.host}:${config.port}/docs`);
|
||||
logger.info(`Log level set to: ${config.logLevel}`);
|
||||
logger.important(`HTTP Service URL: http://${config.host}:${config.port}`);
|
||||
logger.important(`Swagger Docs: http://${config.host}:${config.port}/docs`);
|
||||
logger.important(`Log level set to: ${config.logLevel}`);
|
||||
});
|
||||
|
||||
const shutdown = async () => {
|
||||
|
||||
Reference in New Issue
Block a user