Add log level configuration

This commit is contained in:
Simon Larsen 2024-04-05 17:52:34 +01:00
parent bc1ca32991
commit e11b781fc5
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
8 changed files with 60 additions and 16 deletions

View File

@ -5,6 +5,13 @@ import SubscriptionPlan from 'Common/Types/Billing/SubscriptionPlan';
import { JSONObject } from 'Common/Types/JSON';
import BillingConfig from './BillingConfig';
export enum ConfigLogLevel {
INFO = 'INFO',
WARN = 'WARN',
ERROR = 'ERROR',
DEBUG = 'DEBUG',
}
export const getAllEnvVars: () => JSONObject = (): JSONObject => {
return process.env;
};
@ -139,3 +146,6 @@ export const ClickhouseDatabase: string =
export const GitSha: string = process.env['GIT_SHA'] || 'unknown';
export const AppVersion: string = process.env['APP_VERSION'] || 'unknown';
export const LogLevel: ConfigLogLevel =
(process.env['LOG_LEVEL'] as ConfigLogLevel) || ConfigLogLevel.ERROR;

View File

@ -2,6 +2,7 @@ import { SeverityNumber } from '@opentelemetry/api-logs';
import OneUptimeTelemetry from './Telemetry';
import Exception from 'Common/Types/Exception/Exception';
import { JSONObject } from 'Common/Types/JSON';
import { ConfigLogLevel, LogLevel } from '../EnvironmentConfig';
export type LogBody = string | JSONObject | Exception | Error | unknown;
@ -16,31 +17,51 @@ export default class logger {
}
public static info(message: LogBody): void {
this.emit({
body: message,
severityNumber: SeverityNumber.INFO,
});
if (
LogLevel === ConfigLogLevel.DEBUG ||
LogLevel === ConfigLogLevel.INFO
) {
this.emit({
body: message,
severityNumber: SeverityNumber.INFO,
});
}
}
public static error(message: LogBody): void {
this.emit({
body: message,
severityNumber: SeverityNumber.ERROR,
});
if (
LogLevel === ConfigLogLevel.DEBUG ||
LogLevel === ConfigLogLevel.INFO ||
LogLevel === ConfigLogLevel.WARN ||
LogLevel === ConfigLogLevel.ERROR
) {
this.emit({
body: message,
severityNumber: SeverityNumber.ERROR,
});
}
}
public static warn(message: LogBody): void {
this.emit({
body: message,
severityNumber: SeverityNumber.WARN,
});
if (
LogLevel === ConfigLogLevel.DEBUG ||
LogLevel === ConfigLogLevel.INFO ||
LogLevel === ConfigLogLevel.WARN
) {
this.emit({
body: message,
severityNumber: SeverityNumber.WARN,
});
}
}
public static debug(message: LogBody): void {
this.emit({
body: message,
severityNumber: SeverityNumber.DEBUG,
});
if (LogLevel === ConfigLogLevel.DEBUG) {
this.emit({
body: message,
severityNumber: SeverityNumber.DEBUG,
});
}
}
public static emit(data: {

View File

@ -85,6 +85,7 @@ The following table lists the configurable parameters of the OneUptime chart and
| `internalSmtp.dkimPublicKey` | DKIM Public Key that is set for sending domain | `nil` | |
| `internalSmtp.email` | Email address to send emails from | `nil` | |
| `internalSmtp.name` | Name to send emails from | `nil` | |
| `logLevel` | Can be one of the following - INFO, WARN, ERROR, DEBUG | `ERROR` | |
| `incidents.disableAutomaticCreation` | Disable incident creation (use this when your team is overloaded with incidents or in emergencies) | `false` | |
| `podSecurityContext` | Pod Security Context. Please refer to Kubernetes docuemntation to set these. This chart depends on other bitnami charts. You will have to set security context for those as well | `{}` | |
| `conatinerSecurityContext` | Container Security Context. Please refer to kubernetes documentation to set these. This chart depends on other bitnami charts. You will have to set security context for those as well | `{}` | |

View File

@ -3,6 +3,8 @@
value: {{ $.Values.host }}
- name: OTEL_COLLECTOR_HOST
value: {{ $.Values.openTelemetryCollectorHost }}
- name: LOG_LEVEL
value: {{ $.Values.logLevel }}
- name: FLUENTD_HOST
value: {{ $.Values.fluentdHost }}
- name: HTTP_PROTOCOL

View File

@ -30,6 +30,8 @@ spec:
{{- end }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
env:
- name: LOG_LEVEL
value: {{ $.Values.logLevel }}
- name: PORT
value: {{ $.Values.port.probe | squote }}
- name: OPENTELEMETRY_EXPORTER_OTLP_HEADERS

View File

@ -179,4 +179,6 @@ containerSecurityContext:
podSecurityContext:
# This can be one of the following: DEBUG, INFO, WARN, ERROR
logLevel: ERROR

View File

@ -188,5 +188,9 @@ ACCOUNTS_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
ADMIN_DASHBOARD_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
# This can be one of ERROR, WARN, INFO, DEBUG
LOG_LEVEL=ERROR

View File

@ -9,6 +9,8 @@ x-common-variables: &common-variables
FLUENTD_HOST: ${FLUENTD_HOST}
LOG_LEVEL: ${LOG_LEVEL}
NODE_ENV: ${ENVIRONMENT}
BILLING_ENABLED: ${BILLING_ENABLED}
BILLING_PUBLIC_KEY: ${BILLING_PUBLIC_KEY}