mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
🪵 refactor: Dynamic getLogDirectory
utility for Loggers (#8686)
This commit is contained in:
parent
545a909953
commit
f4facb7d35
5 changed files with 43 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@librechat/data-schemas",
|
||||
"version": "0.0.12",
|
||||
"version": "0.0.13",
|
||||
"description": "Mongoose schemas and models for LibreChat",
|
||||
"type": "module",
|
||||
"main": "dist/index.cjs",
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import path from 'path';
|
||||
import winston from 'winston';
|
||||
import 'winston-daily-rotate-file';
|
||||
import { getLogDirectory } from './utils';
|
||||
|
||||
const logDir = path.join(__dirname, '..', '..', '..', 'api', 'logs');
|
||||
const logDir = getLogDirectory();
|
||||
|
||||
const { NODE_ENV, DEBUG_LOGGING = 'false' } = process.env;
|
||||
|
||||
|
|
37
packages/data-schemas/src/config/utils.ts
Normal file
37
packages/data-schemas/src/config/utils.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Determine the log directory in a cross-compatible way.
|
||||
* Priority:
|
||||
* 1. LIBRECHAT_LOG_DIR environment variable
|
||||
* 2. If running within LibreChat monorepo (when cwd ends with /api), use api/logs
|
||||
* 3. If api/logs exists relative to cwd, use that (for running from project root)
|
||||
* 4. Otherwise, use logs directory relative to process.cwd()
|
||||
*
|
||||
* This avoids using __dirname which is not available in ESM modules
|
||||
*/
|
||||
export const getLogDirectory = (): string => {
|
||||
if (process.env.LIBRECHAT_LOG_DIR) {
|
||||
return process.env.LIBRECHAT_LOG_DIR;
|
||||
}
|
||||
|
||||
const cwd = process.cwd();
|
||||
|
||||
// Check if we're running from within the api directory
|
||||
if (cwd.endsWith('/api') || cwd.endsWith('\\api')) {
|
||||
return path.join(cwd, 'logs');
|
||||
}
|
||||
|
||||
// Check if api/logs exists relative to current directory (running from project root)
|
||||
// We'll just use the path and let the file system create it if needed
|
||||
const apiLogsPath = path.join(cwd, 'api', 'logs');
|
||||
|
||||
// For LibreChat project structure, use api/logs
|
||||
// For external consumers, they should set LIBRECHAT_LOG_DIR
|
||||
if (cwd.includes('LibreChat')) {
|
||||
return apiLogsPath;
|
||||
}
|
||||
|
||||
// Default to logs directory relative to current working directory
|
||||
return path.join(cwd, 'logs');
|
||||
};
|
|
@ -1,9 +1,9 @@
|
|||
import path from 'path';
|
||||
import winston from 'winston';
|
||||
import 'winston-daily-rotate-file';
|
||||
import { redactFormat, redactMessage, debugTraverse, jsonTruncateFormat } from './parsers';
|
||||
import { getLogDirectory } from './utils';
|
||||
|
||||
const logDir = path.join(__dirname, '..', '..', '..', 'api', 'logs');
|
||||
const logDir = getLogDirectory();
|
||||
|
||||
const { NODE_ENV, DEBUG_LOGGING, CONSOLE_JSON, DEBUG_CONSOLE } = process.env;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue