mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01: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
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -48787,7 +48787,7 @@
|
||||||
},
|
},
|
||||||
"packages/data-schemas": {
|
"packages/data-schemas": {
|
||||||
"name": "@librechat/data-schemas",
|
"name": "@librechat/data-schemas",
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-alias": "^5.1.0",
|
"@rollup/plugin-alias": "^5.1.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@librechat/data-schemas",
|
"name": "@librechat/data-schemas",
|
||||||
"version": "0.0.12",
|
"version": "0.0.13",
|
||||||
"description": "Mongoose schemas and models for LibreChat",
|
"description": "Mongoose schemas and models for LibreChat",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import path from 'path';
|
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import 'winston-daily-rotate-file';
|
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;
|
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 from 'winston';
|
||||||
import 'winston-daily-rotate-file';
|
import 'winston-daily-rotate-file';
|
||||||
import { redactFormat, redactMessage, debugTraverse, jsonTruncateFormat } from './parsers';
|
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;
|
const { NODE_ENV, DEBUG_LOGGING, CONSOLE_JSON, DEBUG_CONSOLE } = process.env;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue