Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

DEBUG_MODE

Blue Mouse430a57abaa76
diff --git a/.env.example b/.env.example
index f56da4cb4..ee5cba501 100644
--- a/.env.example
+++ b/.env.example
@@ -45,6 +45,7 @@ SMTP_MOCK=true
PASSWORD=12345678
API_KEY=
+DEBUG_MODE=
# Swetrix CDN for storing files
CDN_URL=http://localhost:5006
diff --git a/apps/selfhosted/src/common/integrations/clickhouse.ts b/apps/selfhosted/src/common/integrations/clickhouse.ts
index 771a971f3..aa145ed39 100644
--- a/apps/selfhosted/src/common/integrations/clickhouse.ts
+++ b/apps/selfhosted/src/common/integrations/clickhouse.ts
@@ -1,5 +1,59 @@
+import type {
+ Logger as _CHLogger,
+ LogParams,
+ ErrorLogParams,
+} from '@clickhouse/client'
+import { createClient, ClickHouseLogLevel } from '@clickhouse/client'
+import { Logger } from '@nestjs/common'
import 'dotenv/config'
-import { createClient } from '@clickhouse/client'
+
+export class CHLogger implements _CHLogger {
+ debug({ module, message, args }: LogParams): void {
+ Logger.debug({
+ type: '@clickhouse/client',
+ module,
+ message,
+ ...args,
+ })
+ }
+
+ trace({ module, message, args }: LogParams) {
+ Logger.log({
+ type: '@clickhouse/client',
+ module,
+ message,
+ ...args,
+ })
+ }
+
+ info({ module, message, args }: LogParams): void {
+ Logger.log({
+ type: '@clickhouse/client',
+ module,
+ message,
+ ...args,
+ })
+ }
+
+ warn({ module, message, args }: LogParams): void {
+ Logger.warn({
+ type: '@clickhouse/client',
+ module,
+ message,
+ ...args,
+ })
+ }
+
+ error({ module, message, args, err }: ErrorLogParams): void {
+ Logger.error({
+ type: '@clickhouse/client',
+ module,
+ message,
+ ...args,
+ err,
+ })
+ }
+}
const clickhouse = createClient({
url: `${process.env.CLICKHOUSE_HOST}:${process.env.CLICKHOUSE_PORT}`,
@@ -22,6 +76,13 @@ const clickhouse = createClient({
wait_for_async_insert: 0, // Return ACK (await) when row was added to the buffer, not flushed to the database
async_insert_busy_timeout_ms: 15000, // 15 seconds; this is how long the buffer will be kept before writing stuff into the database
},
+ log: {
+ LoggerClass: CHLogger,
+ level:
+ process.env.DEBUG_MODE === 'true'
+ ? ClickHouseLogLevel.DEBUG
+ : ClickHouseLogLevel.OFF,
+ },
})
export { clickhouse }