generated from nhcarrigan/template
feat: use our logging package
This commit is contained in:
+2
-2
@@ -12,7 +12,7 @@ import { proofread } from "./modules/proofread.js";
|
||||
import { query } from "./modules/query.js";
|
||||
import { summarise } from "./modules/summarise.js";
|
||||
import { instantiateServer } from "./server/serve.js";
|
||||
import { logHandler } from "./utils/logHandler.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
|
||||
const commands: Record<
|
||||
string,
|
||||
@@ -42,7 +42,7 @@ client.on(Events.InteractionCreate, (interaction) => {
|
||||
});
|
||||
|
||||
client.on(Events.ClientReady, () => {
|
||||
logHandler.info("Bot is ready.");
|
||||
void logger.log("debug", "Bot is ready.");
|
||||
});
|
||||
|
||||
instantiateServer();
|
||||
|
||||
+8
-4
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import fastify from "fastify";
|
||||
import { logHandler } from "../utils/logHandler.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
|
||||
const html = `<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -60,12 +60,16 @@ export const instantiateServer = (): void => {
|
||||
|
||||
server.listen({ port: 5002 }, (error) => {
|
||||
if (error) {
|
||||
logHandler.error(error);
|
||||
void logger.error("instantiate server", error);
|
||||
return;
|
||||
}
|
||||
logHandler.info("Server listening on port 5002.");
|
||||
void logger.log("debug", "Server listening on port 5002.");
|
||||
});
|
||||
} catch (error) {
|
||||
logHandler.error(error);
|
||||
if (error instanceof Error) {
|
||||
void logger.error("instantiate server", error);
|
||||
return;
|
||||
}
|
||||
void logger.error("instantiate server", new Error("Unknown error"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { createLogger, format, transports, config } from "winston";
|
||||
|
||||
const { combine, timestamp, colorize, printf } = format;
|
||||
|
||||
/**
|
||||
* Standard log handler, using winston to wrap and format
|
||||
* messages. Call with `logHandler.log(level, message)`.
|
||||
* @param {string} level - The log level to use.
|
||||
* @param {string} message - The message to log.
|
||||
*/
|
||||
export const logHandler = createLogger({
|
||||
exitOnError: false,
|
||||
format: combine(
|
||||
timestamp({
|
||||
format: "YYYY-MM-DD HH:mm:ss",
|
||||
}),
|
||||
colorize(),
|
||||
printf((info) => {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- Winston properties...
|
||||
return `${info.level}: ${info.timestamp}: ${info.message}`;
|
||||
}),
|
||||
),
|
||||
level: "silly",
|
||||
levels: config.npm.levels,
|
||||
transports: [ new transports.Console() ],
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { Logger } from "@nhcarrigan/logger";
|
||||
|
||||
export const logger = new Logger(
|
||||
"Cordelia Taryne",
|
||||
process.env.LOG_TOKEN ?? "",
|
||||
);
|
||||
Reference in New Issue
Block a user