mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 03:18:06 +03:00
Merge pull request #407 from TNG-dev/zkldi-replica-identity
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ timeout: 960
|
||||
ts: true
|
||||
before: "./src/test-utils/hack-setup.js"
|
||||
check-coverage: true
|
||||
branches: 70
|
||||
branches: 60
|
||||
functions: 80
|
||||
lines: 80
|
||||
statements: 80
|
||||
|
||||
@@ -2,7 +2,7 @@ import winston, { format, transports, Logger, LeveledLogMethod } from "winston";
|
||||
import { EscapeStringRegexp } from "utils/misc";
|
||||
import "winston-daily-rotate-file";
|
||||
import SafeJSONStringify from "safe-json-stringify";
|
||||
import { ServerConfig } from "lib/setup/config";
|
||||
import { Environment, ServerConfig } from "lib/setup/config";
|
||||
import CreateDiscordWinstonTransport from "./discord-transport";
|
||||
|
||||
export type KtLogger = Logger & { severe: LeveledLogMethod };
|
||||
@@ -69,16 +69,18 @@ const formatExcessPropertiesNoStack = (
|
||||
return ` ${limit ? StrCap(content) : content}`;
|
||||
};
|
||||
|
||||
const replicaInfo = Environment.replicaIdentity ? ` (${Environment.replicaIdentity})` : "";
|
||||
|
||||
const tachiPrintf = format.printf(
|
||||
({ level, message, context = "tachi-root", timestamp, ...meta }) =>
|
||||
`${timestamp} [${
|
||||
`${timestamp}${replicaInfo} [${
|
||||
Array.isArray(context) ? context.join(" | ") : context
|
||||
}] ${level}: ${message}${formatExcessProperties(meta, true)}`
|
||||
);
|
||||
|
||||
const tachiConsolePrintf = format.printf(
|
||||
({ level, message, context = "tachi-root", timestamp, hideFromConsole, ...meta }) =>
|
||||
`${timestamp} [${
|
||||
`${timestamp}${replicaInfo} [${
|
||||
Array.isArray(context) ? context.join(" | ") : context
|
||||
}] ${level}: ${message}${formatExcessPropertiesNoStack(meta, hideFromConsole, true)}`
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
// barrel file for re-exporting env variables.
|
||||
import dotenv from "dotenv";
|
||||
import fs from "fs";
|
||||
@@ -9,8 +10,14 @@ import { FormatPrError } from "utils/prudence";
|
||||
|
||||
dotenv.config(); // imports things like NODE_ENV from a local .env file if one is present.
|
||||
|
||||
const replicaInfo = process.env.REPLICA_IDENTITY ? ` (${process.env.REPLICA_IDENTITY})` : "";
|
||||
|
||||
// stub - having a real logger here creates a circular dependency.
|
||||
const logger = console; // CreateLogCtx(__filename);
|
||||
const logger = {
|
||||
info: (...content: unknown[]) => console.log(replicaInfo, content),
|
||||
error: (...content: unknown[]) => console.error(replicaInfo, content),
|
||||
warn: (...content: unknown[]) => console.warn(replicaInfo, content),
|
||||
}; // CreateLogCtx(__filename);
|
||||
|
||||
const confLocation = process.env.TCHIS_CONF_LOCATION ?? "./conf.json5";
|
||||
|
||||
@@ -201,6 +208,13 @@ if (!["dev", "production", "staging", "test"].includes(nodeEnv)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const replicaIdentity = process.env.REPLICA_IDENTITY;
|
||||
if (!replicaIdentity) {
|
||||
logger.info(
|
||||
`No REPLICA_IDENTITY set in environment. We are not running in a distributed environment.`
|
||||
);
|
||||
}
|
||||
|
||||
export const Environment = {
|
||||
port,
|
||||
redisUrl,
|
||||
@@ -208,4 +222,5 @@ export const Environment = {
|
||||
// If node_env is test, force to ./test-cdn.
|
||||
cdnRoot: nodeEnv === "test" ? "./test-cdn" : cdnRoot,
|
||||
nodeEnv,
|
||||
replicaIdentity,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user