Update and fix logging
parent
55da3d877b
commit
8b39da43d1
3
.env.dev
3
.env.dev
|
@ -1,4 +1,5 @@
|
|||
MONGODB_URI=mongodb://root:do_not_use_in_prod@127.0.0.1:27017/admin
|
||||
MONGODB_DATABASE=automod
|
||||
REDIS_URI=redis://127.0.0.1:6379
|
||||
PREFIX=//
|
||||
PREFIX=//
|
||||
NODE_ENV=development
|
|
@ -3,6 +3,9 @@ TOKEN=
|
|||
# Not required for docker deployment, use MONGODB-{USERNAME,PASSWORD} instead
|
||||
# MONGODB_URI=mongodb://
|
||||
|
||||
# Set this if you want to load an additional env file
|
||||
# ENV_FILE=
|
||||
|
||||
MONGODB_USERNAME=automod
|
||||
MONGODB_PASSWORD=
|
||||
MOBGODB_DATABASE=automod
|
||||
|
|
|
@ -24,6 +24,11 @@ if (process.env.NODE_ENV != "production") {
|
|||
config({ path: "../.env.dev" });
|
||||
}
|
||||
|
||||
if (process.env.ENV_FILE) {
|
||||
logger.info("$ENV_FILE is set; Loading additional environment file");
|
||||
config({ path: process.env.ENV_FILE });
|
||||
}
|
||||
|
||||
checkEnv(ENV_VARS);
|
||||
const environment: { [key in (typeof ENV_VARS)[number]]: string } =
|
||||
ENV_VARS.reduce(
|
||||
|
@ -47,11 +52,20 @@ client.events.on("error", (e) =>
|
|||
)}`,
|
||||
),
|
||||
);
|
||||
|
||||
let lastStateUpdate = Date.now();
|
||||
client.events.on("state", (state) => {
|
||||
const stateName = Object.entries(ConnectionState).find(
|
||||
(s) => s[1] == state,
|
||||
)?.[0];
|
||||
logger.info(`Connection state changed to ${state} (${stateName})`);
|
||||
|
||||
const now = Date.now();
|
||||
logger.info(
|
||||
`Connection state changed to ${state} (${stateName}, ${
|
||||
now - lastStateUpdate
|
||||
}ms)`,
|
||||
);
|
||||
lastStateUpdate = now;
|
||||
|
||||
if (state == ConnectionState.Disconnected && !client.options.debug) {
|
||||
logger.warn("Disconnected; Enabling debug logging");
|
||||
|
@ -60,6 +74,7 @@ client.events.on("state", (state) => {
|
|||
|
||||
if (state == ConnectionState.Connected && client.options.debug) {
|
||||
logger.info("Reconnected; Disabling debug logging");
|
||||
client.options.debug = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ export const processMessageCommand = async (message: Message) => {
|
|||
logger.debug(`Received message: ${message.content?.substring(0, 100)}`);
|
||||
|
||||
if (message.server && !(await enabledInServer(message.server, client))) {
|
||||
return logger.info(
|
||||
return logger.debug(
|
||||
`Refusing to interact with server ${message.server.id}`,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ services:
|
|||
- MONGODB_DATABASE=${MONGODB_DATABASE:-automod}
|
||||
- PREFIX=${PREFIX:-/}
|
||||
- TOKEN
|
||||
- NODE_ENV=production
|
||||
depends_on:
|
||||
- db
|
||||
- redis
|
||||
|
|
|
@ -2,5 +2,9 @@ import Log75, { LogLevel } from "log75";
|
|||
|
||||
export function createLogger() {
|
||||
// nice typings
|
||||
return new (Log75 as any).default(LogLevel.Debug) as Log75;
|
||||
return new (Log75 as any).default(
|
||||
process.env.NODE_ENV == "production"
|
||||
? LogLevel.Standard
|
||||
: LogLevel.Debug,
|
||||
) as Log75;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue