feat: add logging
This commit is contained in:
@@ -7,6 +7,7 @@ export interface Environment {
|
||||
TBANK_CA_CERT_PATH?: string;
|
||||
TBANK_GRPC_ENDPOINT: string;
|
||||
TBANK_RATE_LIMIT_PER_SECOND: number;
|
||||
LOG_LEVEL: 'debug' | 'info' | 'warn' | 'error';
|
||||
}
|
||||
|
||||
export function validateEnv(config: Record<string, unknown>): Environment {
|
||||
@@ -19,6 +20,7 @@ export function validateEnv(config: Record<string, unknown>): Environment {
|
||||
config['TBANK_GRPC_ENDPOINT'] ?? 'invest-public-api.tbank.ru:443';
|
||||
const tbankRateLimit = config['TBANK_RATE_LIMIT_PER_SECOND'] ?? 5;
|
||||
const tbankCaCertPath = config['TBANK_CA_CERT_PATH'];
|
||||
const logLevel = config['LOG_LEVEL'] ?? 'info';
|
||||
|
||||
if (typeof databaseUrl !== 'string' || !databaseUrl.startsWith('file:')) {
|
||||
throw new Error('DATABASE_URL must be a SQLite file URL');
|
||||
@@ -76,6 +78,10 @@ export function validateEnv(config: Record<string, unknown>): Environment {
|
||||
throw new Error('TBANK_CA_CERT_PATH must be a file path');
|
||||
}
|
||||
|
||||
if (!['debug', 'info', 'warn', 'error'].includes(logLevel as string)) {
|
||||
throw new Error('LOG_LEVEL must be debug, info, warn, or error');
|
||||
}
|
||||
|
||||
return {
|
||||
DATABASE_URL: databaseUrl,
|
||||
FRONTEND_ORIGIN: parsedOrigin.origin,
|
||||
@@ -87,5 +93,6 @@ export function validateEnv(config: Record<string, unknown>): Environment {
|
||||
: {}),
|
||||
TBANK_GRPC_ENDPOINT: tbankEndpoint,
|
||||
TBANK_RATE_LIMIT_PER_SECOND: parsedTbankRateLimit,
|
||||
LOG_LEVEL: logLevel as Environment['LOG_LEVEL'],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user