diff --git a/plugin-server/src/types.ts b/plugin-server/src/types.ts index 700bf4f6cef89..af3d34f69cc18 100644 --- a/plugin-server/src/types.ts +++ b/plugin-server/src/types.ts @@ -451,9 +451,10 @@ export enum PluginLogEntryType { export enum PluginLogLevel { Full = 0, // all logs - Debug = 1, // all except log - Warn = 2, // all except log and info - Critical = 3, // only error type and system source + Log = 1, // all except debug + Info = 2, // all expect log and debug + Warn = 3, // all except log, debug and info + Critical = 4, // only error type and system source } export interface PluginLogEntry { diff --git a/plugin-server/src/utils/db/db.ts b/plugin-server/src/utils/db/db.ts index cf64f86b600a2..f6999b3caae85 100644 --- a/plugin-server/src/utils/db/db.ts +++ b/plugin-server/src/utils/db/db.ts @@ -1076,10 +1076,9 @@ export class DB { public async queuePluginLogEntry(entry: LogEntryPayload): Promise { const { pluginConfig, source, message, type, timestamp, instanceId } = entry + const configuredLogLevel = pluginConfig.plugin?.log_level || PluginLogLevel.Log - const logLevel = pluginConfig.plugin?.log_level - - if (!shouldStoreLog(logLevel || PluginLogLevel.Full, source, type)) { + if (!shouldStoreLog(configuredLogLevel, type)) { return } diff --git a/plugin-server/src/utils/db/utils.ts b/plugin-server/src/utils/db/utils.ts index a4f940defdefb..de37e8c3f5f67 100644 --- a/plugin-server/src/utils/db/utils.ts +++ b/plugin-server/src/utils/db/utils.ts @@ -6,10 +6,9 @@ import { Counter } from 'prom-client' import { defaultConfig } from '../../config/config' import { KAFKA_PERSON } from '../../config/kafka-topics' -import { BasePerson, Person, RawPerson, TimestampFormat } from '../../types' +import { BasePerson, Person, PluginLogEntryType, PluginLogLevel, RawPerson, TimestampFormat } from '../../types' import { status } from '../../utils/status' import { castTimestampOrNow } from '../../utils/utils' -import { PluginLogEntrySource, PluginLogEntryType, PluginLogLevel } from './../../types' export function unparsePersonPartial(person: Partial): Partial { return { ...(person as BasePerson), ...(person.created_at ? { created_at: person.created_at.toISO() } : {}) } @@ -127,24 +126,19 @@ export function getFinalPostgresQuery(queryString: string, values: any[]): strin return queryString.replace(/\$([0-9]+)/g, (m, v) => JSON.stringify(values[parseInt(v) - 1])) } -export function shouldStoreLog( - pluginLogLevel: PluginLogLevel, - source: PluginLogEntrySource, - type: PluginLogEntryType -): boolean { - if (source === PluginLogEntrySource.System) { - return true +export function shouldStoreLog(pluginLogLevel: PluginLogLevel, type: PluginLogEntryType): boolean { + switch (pluginLogLevel) { + case PluginLogLevel.Full: + return true + case PluginLogLevel.Log: + return type !== PluginLogEntryType.Debug + case PluginLogLevel.Info: + return type !== PluginLogEntryType.Log && type !== PluginLogEntryType.Debug + case PluginLogLevel.Warn: + return type === PluginLogEntryType.Warn || type === PluginLogEntryType.Error + case PluginLogLevel.Critical: + return type === PluginLogEntryType.Error } - - if (pluginLogLevel === PluginLogLevel.Critical) { - return type === PluginLogEntryType.Error - } else if (pluginLogLevel === PluginLogLevel.Warn) { - return type !== PluginLogEntryType.Log && type !== PluginLogEntryType.Info - } else if (pluginLogLevel === PluginLogLevel.Debug) { - return type !== PluginLogEntryType.Log - } - - return true } // keep in sync with posthog/posthog/api/utils.py::safe_clickhouse_string