getting closer
This commit is contained in:
parent
23f7614b29
commit
f8576c0d93
4 changed files with 62 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
|||
* Loki logging configuration for Stock Bot platform
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
import { getEnvVar, getNumericEnvVar, getBooleanEnvVar } from './core';
|
||||
import { getEnvVar, getNumericEnvVar, getBooleanEnvVar, createConfigLoader, validateConfig } from './core';
|
||||
|
||||
/**
|
||||
* Loki configuration schema
|
||||
|
|
@ -49,11 +49,27 @@ function parseLabels(labelsStr?: string): Record<string, string> {
|
|||
return labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default logging configuration
|
||||
*/
|
||||
const defaultLoggingConfig: LoggingConfig = {
|
||||
level: 'info',
|
||||
console: true,
|
||||
loki: {
|
||||
host: 'localhost',
|
||||
port: 3100,
|
||||
retentionDays: 30,
|
||||
labels: {},
|
||||
batchSize: 100,
|
||||
flushIntervalMs: 5000
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Load logging configuration from environment variables
|
||||
*/
|
||||
export function loadLoggingConfig(): LoggingConfig {
|
||||
return {
|
||||
const config = {
|
||||
level: (getEnvVar('LOG_LEVEL') || 'info') as 'debug' | 'info' | 'warn' | 'error',
|
||||
console: getBooleanEnvVar('LOG_CONSOLE', true),
|
||||
loki: {
|
||||
|
|
@ -67,8 +83,19 @@ export function loadLoggingConfig(): LoggingConfig {
|
|||
flushIntervalMs: getNumericEnvVar('LOKI_FLUSH_INTERVAL_MS', 5000)
|
||||
}
|
||||
};
|
||||
|
||||
return validateConfig(config, loggingConfigSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a dynamic configuration loader for logging
|
||||
*/
|
||||
export const createLoggingConfig = createConfigLoader<typeof defaultLoggingConfig>(
|
||||
'logging',
|
||||
loggingConfigSchema,
|
||||
defaultLoggingConfig
|
||||
);
|
||||
|
||||
/**
|
||||
* Singleton logging configuration
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue