no idea- added loki and other stuff to market-data-gateway, also added config lib
This commit is contained in:
parent
b957fb99aa
commit
1b71fc87ab
72 changed files with 6178 additions and 153 deletions
75
libs/config/src/logging.ts
Normal file
75
libs/config/src/logging.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Loki logging configuration for Stock Bot platform
|
||||
*/
|
||||
import { z } from 'zod';
|
||||
import { getEnvVar, getNumericEnvVar, getBooleanEnvVar } from './core';
|
||||
|
||||
/**
|
||||
* Loki configuration schema
|
||||
*/
|
||||
export const lokiConfigSchema = z.object({
|
||||
host: z.string().default('localhost'),
|
||||
port: z.number().default(3100),
|
||||
username: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
retentionDays: z.number().default(30),
|
||||
labels: z.record(z.string()).default({}),
|
||||
batchSize: z.number().default(100),
|
||||
flushIntervalMs: z.number().default(5000)
|
||||
});
|
||||
|
||||
export type LokiConfig = z.infer<typeof lokiConfigSchema>;
|
||||
|
||||
/**
|
||||
* Logging configuration schema
|
||||
*/
|
||||
export const loggingConfigSchema = z.object({
|
||||
level: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
|
||||
console: z.boolean().default(true),
|
||||
loki: lokiConfigSchema
|
||||
});
|
||||
|
||||
export type LoggingConfig = z.infer<typeof loggingConfigSchema>;
|
||||
|
||||
/**
|
||||
* Parse labels from environment variable string
|
||||
* Format: key1=value1,key2=value2
|
||||
*/
|
||||
function parseLabels(labelsStr?: string): Record<string, string> {
|
||||
if (!labelsStr) return {};
|
||||
|
||||
const labels: Record<string, string> = {};
|
||||
labelsStr.split(',').forEach(labelPair => {
|
||||
const [key, value] = labelPair.trim().split('=');
|
||||
if (key && value) {
|
||||
labels[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load logging configuration from environment variables
|
||||
*/
|
||||
export function loadLoggingConfig(): LoggingConfig {
|
||||
return {
|
||||
level: (getEnvVar('LOG_LEVEL') || 'info') as 'debug' | 'info' | 'warn' | 'error',
|
||||
console: getBooleanEnvVar('LOG_CONSOLE', true),
|
||||
loki: {
|
||||
host: getEnvVar('LOKI_HOST') || 'localhost',
|
||||
port: getNumericEnvVar('LOKI_PORT', 3100),
|
||||
username: getEnvVar('LOKI_USERNAME'),
|
||||
password: getEnvVar('LOKI_PASSWORD'),
|
||||
retentionDays: getNumericEnvVar('LOKI_RETENTION_DAYS', 30),
|
||||
labels: parseLabels(getEnvVar('LOKI_LABELS')),
|
||||
batchSize: getNumericEnvVar('LOKI_BATCH_SIZE', 100),
|
||||
flushIntervalMs: getNumericEnvVar('LOKI_FLUSH_INTERVAL_MS', 5000)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton logging configuration
|
||||
*/
|
||||
export const loggingConfig = loadLoggingConfig();
|
||||
Loading…
Add table
Add a link
Reference in a new issue