mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
🪵 fix: Standardize Logging Directory with Environment-Aware Resolution (#11000)
* refactor: Implement getLogDir function to set log directory based on environment variables and execution context (Docker or local) * fix: Adjust Dockerfile to create the correct log directory path for consistency
This commit is contained in:
parent
a0df7e8df1
commit
b4459ab564
3 changed files with 57 additions and 3 deletions
|
|
@ -30,7 +30,7 @@ RUN \
|
||||||
# Allow mounting of these files, which have no default
|
# Allow mounting of these files, which have no default
|
||||||
touch .env ; \
|
touch .env ; \
|
||||||
# Create directories for the volumes to inherit the correct permissions
|
# Create directories for the volumes to inherit the correct permissions
|
||||||
mkdir -p /app/client/public/images /app/api/logs /app/uploads ; \
|
mkdir -p /app/client/public/images /app/logs /app/uploads ; \
|
||||||
npm config set fetch-retry-maxtimeout 600000 ; \
|
npm config set fetch-retry-maxtimeout 600000 ; \
|
||||||
npm config set fetch-retries 5 ; \
|
npm config set fetch-retries 5 ; \
|
||||||
npm config set fetch-retry-mintimeout 15000 ; \
|
npm config set fetch-retry-mintimeout 15000 ; \
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,35 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
require('winston-daily-rotate-file');
|
require('winston-daily-rotate-file');
|
||||||
|
|
||||||
const logDir = path.join(__dirname, '..', 'logs');
|
/**
|
||||||
|
* Determine the log directory.
|
||||||
|
* Priority:
|
||||||
|
* 1. LIBRECHAT_LOG_DIR environment variable (allows user override)
|
||||||
|
* 2. /app/logs if running in Docker (bind-mounted with correct permissions)
|
||||||
|
* 3. api/logs relative to this file (local development)
|
||||||
|
*/
|
||||||
|
const getLogDir = () => {
|
||||||
|
if (process.env.LIBRECHAT_LOG_DIR) {
|
||||||
|
return process.env.LIBRECHAT_LOG_DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if running in Docker container (cwd is /app)
|
||||||
|
if (process.cwd() === '/app') {
|
||||||
|
const dockerLogDir = '/app/logs';
|
||||||
|
// Ensure the directory exists
|
||||||
|
if (!fs.existsSync(dockerLogDir)) {
|
||||||
|
fs.mkdirSync(dockerLogDir, { recursive: true });
|
||||||
|
}
|
||||||
|
return dockerLogDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local development: use api/logs relative to this file
|
||||||
|
return path.join(__dirname, '..', 'logs');
|
||||||
|
};
|
||||||
|
|
||||||
|
const logDir = getLogDir();
|
||||||
|
|
||||||
const { NODE_ENV, DEBUG_LOGGING = false } = process.env;
|
const { NODE_ENV, DEBUG_LOGGING = false } = process.env;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,36 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
require('winston-daily-rotate-file');
|
require('winston-daily-rotate-file');
|
||||||
const { redactFormat, redactMessage, debugTraverse, jsonTruncateFormat } = require('./parsers');
|
const { redactFormat, redactMessage, debugTraverse, jsonTruncateFormat } = require('./parsers');
|
||||||
|
|
||||||
const logDir = path.join(__dirname, '..', 'logs');
|
/**
|
||||||
|
* Determine the log directory.
|
||||||
|
* Priority:
|
||||||
|
* 1. LIBRECHAT_LOG_DIR environment variable (allows user override)
|
||||||
|
* 2. /app/logs if running in Docker (bind-mounted with correct permissions)
|
||||||
|
* 3. api/logs relative to this file (local development)
|
||||||
|
*/
|
||||||
|
const getLogDir = () => {
|
||||||
|
if (process.env.LIBRECHAT_LOG_DIR) {
|
||||||
|
return process.env.LIBRECHAT_LOG_DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if running in Docker container (cwd is /app)
|
||||||
|
if (process.cwd() === '/app') {
|
||||||
|
const dockerLogDir = '/app/logs';
|
||||||
|
// Ensure the directory exists
|
||||||
|
if (!fs.existsSync(dockerLogDir)) {
|
||||||
|
fs.mkdirSync(dockerLogDir, { recursive: true });
|
||||||
|
}
|
||||||
|
return dockerLogDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local development: use api/logs relative to this file
|
||||||
|
return path.join(__dirname, '..', 'logs');
|
||||||
|
};
|
||||||
|
|
||||||
|
const logDir = getLogDir();
|
||||||
|
|
||||||
const { NODE_ENV, DEBUG_LOGGING = true, CONSOLE_JSON = false, DEBUG_CONSOLE = false } = process.env;
|
const { NODE_ENV, DEBUG_LOGGING = true, CONSOLE_JSON = false, DEBUG_CONSOLE = false } = process.env;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue