mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-24 11:03:17 -04:00
chore(api): add log level configuration
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
55deb556ce
commit
a477643d7d
@@ -4,7 +4,12 @@
|
||||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="./reset.d.ts" />
|
||||
import { build } from './app';
|
||||
import { FREECODECAMP_NODE_ENV, HOST, PORT } from './utils/env';
|
||||
import {
|
||||
FREECODECAMP_NODE_ENV,
|
||||
FCC_API_LOG_LEVEL,
|
||||
HOST,
|
||||
PORT
|
||||
} from './utils/env';
|
||||
|
||||
const envToLogger = {
|
||||
development: {
|
||||
@@ -15,10 +20,9 @@ const envToLogger = {
|
||||
ignore: 'pid,hostname'
|
||||
}
|
||||
},
|
||||
level: 'debug'
|
||||
level: FCC_API_LOG_LEVEL
|
||||
},
|
||||
// TODO: is this the right level for production or should we use 'error'?
|
||||
production: { level: 'fatal' },
|
||||
production: { level: FCC_API_LOG_LEVEL },
|
||||
test: undefined
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import assert from 'node:assert';
|
||||
import path from 'node:path';
|
||||
import { config } from 'dotenv';
|
||||
import { LogLevel } from 'fastify';
|
||||
|
||||
const envPath = path.resolve(__dirname, '../../../.env');
|
||||
const { error } = config({ path: envPath });
|
||||
@@ -57,6 +58,25 @@ assert.ok(process.env.SHOW_UPCOMING_CHANGES);
|
||||
assert.ok(process.env.MONGOHQ_URL);
|
||||
assert.ok(process.env.COOKIE_SECRET);
|
||||
|
||||
const LOG_LEVELS: LogLevel[] = [
|
||||
'fatal',
|
||||
'error',
|
||||
'warn',
|
||||
'info',
|
||||
'debug',
|
||||
'trace',
|
||||
'silent'
|
||||
] as const;
|
||||
|
||||
function assertLogLevel(level: unknown): level is LogLevel {
|
||||
return typeof level === 'string' && LOG_LEVELS.includes(level);
|
||||
}
|
||||
|
||||
assert.ok(
|
||||
assertLogLevel(process.env.FCC_API_LOG_LEVEL),
|
||||
`FCC_API_LOG_LEVEL must be one of ${LOG_LEVELS.join(',')}. Found ${process.env.FCC_API_LOG_LEVEL}`
|
||||
);
|
||||
|
||||
if (process.env.FREECODECAMP_NODE_ENV !== 'development') {
|
||||
assert.ok(process.env.SES_ID);
|
||||
assert.ok(process.env.SES_SECRET);
|
||||
@@ -137,6 +157,7 @@ export const FCC_ENABLE_EXAM_ENVIRONMENT =
|
||||
process.env.FCC_ENABLE_EXAM_ENVIRONMENT === 'true';
|
||||
export const FCC_ENABLE_SENTRY_ROUTES =
|
||||
process.env.FCC_ENABLE_SENTRY_ROUTES === 'true';
|
||||
export const FCC_API_LOG_LEVEL = process.env.FCC_API_LOG_LEVEL;
|
||||
export const SENTRY_DSN =
|
||||
process.env.SENTRY_DSN === 'dsn_from_sentry_dashboard'
|
||||
? ''
|
||||
|
||||
@@ -71,6 +71,7 @@ FCC_ENABLE_DEV_LOGIN_MODE=true
|
||||
FCC_ENABLE_SHADOW_CAPTURE=false
|
||||
FCC_ENABLE_EXAM_ENVIRONMENT=false
|
||||
FCC_ENABLE_SENTRY_ROUTES=false
|
||||
FCC_API_LOG_LEVEL=debug
|
||||
|
||||
# Email
|
||||
# use ses in production
|
||||
|
||||
Reference in New Issue
Block a user