feat: structured logging (JSON) (#5118)

This commit is contained in:
Cassandra 2024-09-24 11:51:21 +02:00 committed by GitHub
parent dd75890364
commit b287a25de7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 186 additions and 239 deletions

View file

@ -90,8 +90,7 @@ const Monitor = require("./model/monitor");
const User = require("./model/user");
log.debug("server", "Importing Settings");
const { getSettings, setSettings, setting, initJWTSecret, checkLogin, doubleCheckPassword, shake256, SHAKE256_LENGTH, allowDevAllOrigin,
} = require("./util-server");
const { initJWTSecret, checkLogin, doubleCheckPassword, shake256, SHAKE256_LENGTH, allowDevAllOrigin } = require("./util-server");
log.debug("server", "Importing Notification");
const { Notification } = require("./notification");
@ -201,7 +200,7 @@ let needSetup = false;
// Entry Page
app.get("/", async (request, response) => {
let hostname = request.hostname;
if (await setting("trustProxy")) {
if (await Settings.get("trustProxy")) {
const proxy = request.headers["x-forwarded-host"];
if (proxy) {
hostname = proxy;
@ -281,7 +280,7 @@ let needSetup = false;
// Robots.txt
app.get("/robots.txt", async (_request, response) => {
let txt = "User-agent: *\nDisallow:";
if (!await setting("searchEngineIndex")) {
if (!await Settings.get("searchEngineIndex")) {
txt += " /";
}
response.setHeader("Content-Type", "text/plain");
@ -1325,7 +1324,7 @@ let needSetup = false;
socket.on("getSettings", async (callback) => {
try {
checkLogin(socket);
const data = await getSettings("general");
const data = await Settings.getSettings("general");
if (!data.serverTimezone) {
data.serverTimezone = await server.getTimezone();
@ -1353,7 +1352,7 @@ let needSetup = false;
// Disabled Auth + Want to Enable Auth => No Check
// Enabled Auth + Want to Disable Auth => Check!!
// Enabled Auth + Want to Enable Auth => No Check
const currentDisabledAuth = await setting("disableAuth");
const currentDisabledAuth = await Settings.get("disableAuth");
if (!currentDisabledAuth && data.disableAuth) {
await doubleCheckPassword(socket, currentPassword);
}
@ -1367,7 +1366,7 @@ let needSetup = false;
const previousChromeExecutable = await Settings.get("chromeExecutable");
const previousNSCDStatus = await Settings.get("nscd");
await setSettings("general", data);
await Settings.setSettings("general", data);
server.entryPage = data.entryPage;
// Also need to apply timezone globally
@ -1463,7 +1462,7 @@ let needSetup = false;
});
} catch (e) {
console.error(e);
log.error("server", e);
callback({
ok: false,
@ -1576,7 +1575,7 @@ let needSetup = false;
// ***************************
log.debug("auth", "check auto login");
if (await setting("disableAuth")) {
if (await Settings.get("disableAuth")) {
log.info("auth", "Disabled Auth: auto login to admin");
await afterLogin(socket, await R.findOne("user"));
socket.emit("autoLogin");