Skip to content

Commit

Permalink
Longer default rotate for old log files in Backend, closes #1421.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwod committed Oct 25, 2023
1 parent 1d68855 commit f58bf93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions new-backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ BROWSER=
# Allowed values: ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < MARK < OFF
LOG_LEVEL=all

# Number of older log files to keep. Note that they're configured to rotate daily.
#LOG_NUM_BACKUPS=14

# If true, all the logs files (except for the current one) will be gzipped.
#LOG_COMPRESS_BACKUPS=false

# Select where the log will be printed. Valid appenders are "console" and "file".
# "console" will print output to stdout.
# "file" will print to a file – logs/output.log.
Expand Down
16 changes: 15 additions & 1 deletion new-backend/server/common/utils/hajkLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const uniqueInstance =
? `_${process.env.HAJK_INSTANCE_ID}`
: "";

const commonDateFileOptions = {
compress: process.env.LOG_COMPRESS_BACKUPS === "true", // Should the backups be gzipped?
numBackups: !isNaN(Number.parseInt(process.env.LOG_NUM_BACKUPS)) // Number of backup files to keep. Backups rotate on a daily basis.
? Number.parseInt(process.env.LOG_NUM_BACKUPS)
: 14,
mode: 0o644, // The mode in octal format. We want to give the read permission to everyone, hence 644.
};

// Next, configure the log4js singleton. Those settings will be available for
// all other imports of log4js in this project.
log4js.configure({
Expand All @@ -16,7 +24,11 @@ log4js.configure({
// Console appender will print to stdout
console: { type: "stdout" },
// File appender will print to a log file, rotating it each day.
file: { type: "dateFile", filename: `logs/output${uniqueInstance}.log` },
file: {
type: "dateFile",
filename: `logs/output${uniqueInstance}.log`,
...commonDateFileOptions,
},
// Another file appender, specifically to log events that modify Hajk's layers/maps
adminEventLog: {
type: "dateFile",
Expand All @@ -27,12 +39,14 @@ log4js.configure({
type: "pattern",
pattern: "[%d] %m",
},
...commonDateFileOptions,
},
// Appender used for writing access logs. Rotates daily.
accessLog: {
type: "dateFile",
filename: `logs/access${uniqueInstance}.log`,
layout: { type: "messagePassThrough" },
...commonDateFileOptions,
},
},
// Categories specify _which appender is used with respective logger_. E.g., if we create
Expand Down

0 comments on commit f58bf93

Please sign in to comment.