feat: add ability to change application logs location (#31926)

Fixes [31877](https://github.com/appsmithorg/appsmith/issues/31877) 

```
sudo docker run -it -d --name ap -e APPSMITH_LOG_DIR=/logs --pull always appsmith/appsmith-dp:ce-31926


(base) ➜  appsmith-ee git:(release) ✗ docker exec -it -u root ap bash
root@3d17510be0d7:/opt/appsmith# ls /logs/*
/logs/backend:
backend-3d17510be0d7.log

/logs/editor:
access-3d17510be0d7.log  error-3d17510be0d7.log

/logs/rts:
rts-3d17510be0d7.log
root@3d17510be0d7:/opt/appsmith#

```
This commit is contained in:
Goutham Pratapa 2024-03-20 19:45:48 +05:30 committed by GitHub
parent 0b3a2d298b
commit d3acb4ba8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 16 additions and 15 deletions

View File

@ -24,7 +24,7 @@ public class CleanUpOldLogs {
final long cutoffTime = System.currentTimeMillis() - CUTOFF_AGE;
try (Stream<Path> walk = Files.walk(Paths.get("/appsmith-stacks/logs"))) {
try (Stream<Path> walk = Files.walk(Paths.get(System.getenv("APPSMITH_LOG_DIR")))) {
walk.filter(path -> {
try {
return Files.isRegularFile(path)

View File

@ -10,9 +10,9 @@ username=%(ENV_APPSMITH_SUPERVISOR_USER)s
password=%(ENV_APPSMITH_SUPERVISOR_PASSWORD)s
[supervisord]
logfile=/appsmith-stacks/logs/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile=%(ENV_APPSMITH_LOG_DIR)s/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=%(ENV_TMP)s/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/appsmith-stacks/logs/supervisor ; ('AUTO' child log dir, default $TEMP)
childlogdir=%(ENV_APPSMITH_LOG_DIR)s/supervisor ; ('AUTO' child log dir, default $TEMP)
stdout_logfile_maxbytes = 0
stderr_logfile_maxbytes = 0

View File

@ -454,7 +454,7 @@ function setup_auto_heal(){
if [[ ${APPSMITH_AUTO_HEAL-} = 1 ]]; then
# By default APPSMITH_AUTO_HEAL=0
# To enable auto heal set APPSMITH_AUTO_HEAL=1
bash /opt/appsmith/auto_heal.sh $APPSMITH_AUTO_HEAL_CURL_TIMEOUT >> /appsmith-stacks/logs/cron/auto_heal.log 2>&1 &
bash /opt/appsmith/auto_heal.sh $APPSMITH_AUTO_HEAL_CURL_TIMEOUT >> "$APPSMITH_LOG_DIR"/cron/auto_heal.log 2>&1 &
fi
}
@ -490,7 +490,8 @@ configure_supervisord
mkdir -p /appsmith-stacks/data/{backup,restore} /appsmith-stacks/ssl
# Create sub-directory to store services log in the container mounting folder
mkdir -p /appsmith-stacks/logs/{supervisor,backend,cron,editor,rts,mongodb,redis,postgres,appsmithctl}
export APPSMITH_LOG_DIR="${APPSMITH_LOG_DIR:-/appsmith-stacks/logs}"
mkdir -p "$APPSMITH_LOG_DIR"/{supervisor,backend,cron,editor,rts,mongodb,redis,postgres,appsmithctl}
setup_auto_heal

View File

@ -1,7 +1,7 @@
import atexit
import logging
import os
import shutil
import os.path
import subprocess
import time
import urllib.error
@ -10,7 +10,7 @@ import urllib.request
LOADING_PAGE_EDITOR = os.getenv("WWW_PATH") + '/loading.html'
BACKEND_HEALTH_ENDPOINT = "http://localhost:8080/api/v1/health"
LOG_FILE = r'/appsmith-stacks/logs/backend/starting_page_init.log'
LOG_FILE = os.path.join(os.getenv("APPSMITH_LOG_DIR"), "backend", "starting_page_init.log")
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(filename = LOG_FILE, level = logging.NOTSET, format = LOG_FORMAT)

View File

@ -6,7 +6,7 @@ autostart=true
autorestart=true
startsecs=20
startretries=3
stdout_logfile=/appsmith-stacks/logs/%(program_name)s/%(program_name)s-%(ENV_HOSTNAME)s.log
stdout_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/%(program_name)s-%(ENV_HOSTNAME)s.log
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stderr_logfile_maxbytes=10MB

View File

@ -5,8 +5,8 @@ autostart=true
autorestart=true
startsecs=0
startretries=3
stdout_logfile=/appsmith-stacks/logs/%(program_name)s/access-%(ENV_HOSTNAME)s.log
stderr_logfile=/appsmith-stacks/logs/%(program_name)s/error-%(ENV_HOSTNAME)s.log
stdout_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/access-%(ENV_HOSTNAME)s.log
stderr_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/error-%(ENV_HOSTNAME)s.log
stdout_logfile_maxbytes=10MB
stderr_logfile_maxbytes=10MB
stdout_logfile_backups=2

View File

@ -6,7 +6,7 @@ autostart=true
autorestart=true
startsecs=0
startretries=3
stdout_logfile=/appsmith-stacks/logs/%(program_name)s/%(program_name)s-%(ENV_HOSTNAME)s.log
stdout_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/%(program_name)s-%(ENV_HOSTNAME)s.log
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stderr_logfile_maxbytes=10MB

View File

@ -1,12 +1,12 @@
[program:mongodb]
directory=/appsmith-stacks/data/mongodb
command=mongod --port 27017 --dbpath . --logpath /appsmith-stacks/logs/%(program_name)s/db.log --replSet mr1 --keyFile %(ENV_MONGODB_TMP_KEY_PATH)s --bind_ip localhost
command=mongod --port 27017 --dbpath . --logpath %(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/db.log --replSet mr1 --keyFile %(ENV_MONGODB_TMP_KEY_PATH)s --bind_ip localhost
priority=10
autostart=true
autorestart=true
startsecs=10
startretries=3
stdout_logfile=/appsmith-stacks/logs/%(program_name)s/%(program_name)s.log
stdout_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/%(program_name)s.log
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stderr_logfile_maxbytes=10MB

View File

@ -5,7 +5,7 @@ command=/opt/appsmith/run-postgres.sh
autostart=true
autorestart=true
startretries=3
stdout_logfile=/appsmith-stacks/logs/%(program_name)s/%(program_name)s.log
stdout_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/%(program_name)s.log
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stderr_logfile_maxbytes=10MB

View File

@ -8,7 +8,7 @@ autostart=true
autorestart=true
startsecs=0
startretries=3
stdout_logfile=/appsmith-stacks/logs/%(program_name)s/%(program_name)s.log
stdout_logfile=%(ENV_APPSMITH_LOG_DIR)s/%(program_name)s/%(program_name)s.log
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stderr_logfile_maxbytes=10MB