@urga-panel/ur-panels-core 1.0.27 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ export interface DatabaseTransportOptions {
4
4
  levels?: LogLevel[];
5
5
  minLevel?: LogLevel;
6
6
  getDatabaseService: () => any;
7
- collectionName?: string;
7
+ appTag: string;
8
8
  batchSize?: number;
9
9
  flushInterval?: number;
10
10
  }
@@ -14,6 +14,7 @@ export declare class DatabaseTransport implements ILogTransport {
14
14
  minLevel?: LogLevel;
15
15
  private getDatabaseService;
16
16
  private collectionName;
17
+ private appTag;
17
18
  private batchSize;
18
19
  private flushInterval;
19
20
  private logBuffer;
@@ -4,6 +4,7 @@ export class DatabaseTransport {
4
4
  minLevel;
5
5
  getDatabaseService;
6
6
  collectionName;
7
+ appTag;
7
8
  batchSize;
8
9
  flushInterval;
9
10
  logBuffer = [];
@@ -16,14 +17,22 @@ export class DatabaseTransport {
16
17
  error: 4
17
18
  };
18
19
  constructor(options) {
20
+ // APP_TAG zorunlu, yoksa hata ver
21
+ if (!options.appTag || options.appTag.trim() === '') {
22
+ throw new Error('[DatabaseTransport] appTag is required! Set APP_TAG environment variable.');
23
+ }
24
+ this.appTag = options.appTag;
19
25
  this.getDatabaseService = options.getDatabaseService;
20
- this.collectionName = options.collectionName || "logs";
26
+ // Collection name: {appTag} formatında (örn: global-web)
27
+ // Database: "logs" sabit database kullanılır
28
+ this.collectionName = this.appTag;
21
29
  this.batchSize = options.batchSize || 10;
22
30
  this.flushInterval = options.flushInterval || 5000; // 5 saniye
23
31
  if (options.levels)
24
32
  this.levels = options.levels;
25
33
  if (options.minLevel)
26
34
  this.minLevel = options.minLevel;
35
+ console.log(`[DatabaseTransport] Initialized with appTag: ${this.appTag}, database: logs, collection: ${this.collectionName}`);
27
36
  // Periyodik flush başlat
28
37
  this.startFlushTimer();
29
38
  }
@@ -56,7 +65,8 @@ export class DatabaseTransport {
56
65
  console.error('[DatabaseTransport] DatabaseService not ready');
57
66
  return;
58
67
  }
59
- const db = dbService.client.db();
68
+ // "logs" database'ini kullan (tüm log'lar buraya)
69
+ const db = dbService.client.db('logs');
60
70
  const logsCollection = db.collection(this.collectionName);
61
71
  const documents = this.logBuffer.map(entry => ({
62
72
  timestamp: entry.timestamp,
@@ -65,6 +75,7 @@ export class DatabaseTransport {
65
75
  namespace: entry.namespace,
66
76
  message: entry.message,
67
77
  args: entry.args,
78
+ appTag: this.appTag, // Hangi uygulamadan geldiği
68
79
  createdAt: new Date()
69
80
  }));
70
81
  await logsCollection.insertMany(documents);
@@ -6,6 +6,7 @@ export interface EnvLogConfig {
6
6
  LOG_NAMESPACES?: string;
7
7
  LOG_DATABASE_ENABLED?: string;
8
8
  LOG_DATABASE_LEVELS?: string;
9
+ APP_TAG?: string;
9
10
  }
10
11
  /**
11
12
  * Environment variable'lardan LogService config'i oluşturur
@@ -24,4 +25,5 @@ export declare function parseLogConfigFromEnv(env: EnvLogConfig): Partial<LogSer
24
25
  export declare function getDatabaseTransportConfigFromEnv(env: EnvLogConfig): {
25
26
  enabled: boolean;
26
27
  levels?: LogLevel[];
28
+ appTag?: string;
27
29
  };
@@ -45,6 +45,15 @@ export function parseLogConfigFromEnv(env) {
45
45
  */
46
46
  export function getDatabaseTransportConfigFromEnv(env) {
47
47
  const enabled = env.LOG_DATABASE_ENABLED === 'true';
48
+ // APP_TAG kontrolü - enabled ise zorunlu
49
+ let appTag;
50
+ if (enabled) {
51
+ if (!env.APP_TAG || env.APP_TAG.trim() === '') {
52
+ console.error('[DatabaseTransport] APP_TAG is required when LOG_DATABASE_ENABLED=true');
53
+ return { enabled: false }; // APP_TAG yoksa database logging'i devre dışı bırak
54
+ }
55
+ appTag = env.APP_TAG.trim();
56
+ }
48
57
  let levels;
49
58
  if (env.LOG_DATABASE_LEVELS) {
50
59
  levels = env.LOG_DATABASE_LEVELS
@@ -56,5 +65,5 @@ export function getDatabaseTransportConfigFromEnv(env) {
56
65
  // Varsayılan: sadece warn ve error
57
66
  levels = ['warn', 'error'];
58
67
  }
59
- return { enabled, levels };
68
+ return { enabled, levels, appTag };
60
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urga-panel/ur-panels-core",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -5,7 +5,7 @@ export interface DatabaseTransportOptions {
5
5
  levels?: LogLevel[];
6
6
  minLevel?: LogLevel;
7
7
  getDatabaseService: () => any; // DatabaseService'i almak için callback
8
- collectionName?: string; // Varsayılan: "logs"
8
+ appTag: string; // ZORUNLU: Uygulama tag'i (örn: "global-web", "kurs-template")
9
9
  batchSize?: number; // Toplu yazma için
10
10
  flushInterval?: number; // ms cinsinden
11
11
  }
@@ -17,6 +17,7 @@ export class DatabaseTransport implements ILogTransport {
17
17
 
18
18
  private getDatabaseService: () => any;
19
19
  private collectionName: string;
20
+ private appTag: string;
20
21
  private batchSize: number;
21
22
  private flushInterval: number;
22
23
  private logBuffer: ILogEntry[] = [];
@@ -31,14 +32,24 @@ export class DatabaseTransport implements ILogTransport {
31
32
  };
32
33
 
33
34
  constructor(options: DatabaseTransportOptions) {
35
+ // APP_TAG zorunlu, yoksa hata ver
36
+ if (!options.appTag || options.appTag.trim() === '') {
37
+ throw new Error('[DatabaseTransport] appTag is required! Set APP_TAG environment variable.');
38
+ }
39
+
40
+ this.appTag = options.appTag;
34
41
  this.getDatabaseService = options.getDatabaseService;
35
- this.collectionName = options.collectionName || "logs";
42
+ // Collection name: {appTag} formatında (örn: global-web)
43
+ // Database: "logs" sabit database kullanılır
44
+ this.collectionName = this.appTag;
36
45
  this.batchSize = options.batchSize || 10;
37
46
  this.flushInterval = options.flushInterval || 5000; // 5 saniye
38
47
 
39
48
  if (options.levels) this.levels = options.levels;
40
49
  if (options.minLevel) this.minLevel = options.minLevel;
41
50
 
51
+ console.log(`[DatabaseTransport] Initialized with appTag: ${this.appTag}, database: logs, collection: ${this.collectionName}`);
52
+
42
53
  // Periyodik flush başlat
43
54
  this.startFlushTimer();
44
55
  }
@@ -78,7 +89,8 @@ export class DatabaseTransport implements ILogTransport {
78
89
  return;
79
90
  }
80
91
 
81
- const db = dbService.client.db();
92
+ // "logs" database'ini kullan (tüm log'lar buraya)
93
+ const db = dbService.client.db('logs');
82
94
  const logsCollection = db.collection(this.collectionName);
83
95
 
84
96
  const documents = this.logBuffer.map(entry => ({
@@ -88,6 +100,7 @@ export class DatabaseTransport implements ILogTransport {
88
100
  namespace: entry.namespace,
89
101
  message: entry.message,
90
102
  args: entry.args,
103
+ appTag: this.appTag, // Hangi uygulamadan geldiği
91
104
  createdAt: new Date()
92
105
  }));
93
106
 
@@ -8,6 +8,7 @@ export interface EnvLogConfig {
8
8
  LOG_NAMESPACES?: string;
9
9
  LOG_DATABASE_ENABLED?: string;
10
10
  LOG_DATABASE_LEVELS?: string;
11
+ APP_TAG?: string; // Uygulama tag'i (zorunlu eğer database logging enabled ise)
11
12
  }
12
13
 
13
14
  /**
@@ -60,9 +61,19 @@ export function parseLogConfigFromEnv(env: EnvLogConfig): Partial<LogServiceConf
60
61
  /**
61
62
  * DatabaseTransport için config döner
62
63
  */
63
- export function getDatabaseTransportConfigFromEnv(env: EnvLogConfig): { enabled: boolean, levels?: LogLevel[] } {
64
+ export function getDatabaseTransportConfigFromEnv(env: EnvLogConfig): { enabled: boolean, levels?: LogLevel[], appTag?: string } {
64
65
  const enabled = env.LOG_DATABASE_ENABLED === 'true';
65
66
 
67
+ // APP_TAG kontrolü - enabled ise zorunlu
68
+ let appTag: string | undefined;
69
+ if (enabled) {
70
+ if (!env.APP_TAG || env.APP_TAG.trim() === '') {
71
+ console.error('[DatabaseTransport] APP_TAG is required when LOG_DATABASE_ENABLED=true');
72
+ return { enabled: false }; // APP_TAG yoksa database logging'i devre dışı bırak
73
+ }
74
+ appTag = env.APP_TAG.trim();
75
+ }
76
+
66
77
  let levels: LogLevel[] | undefined;
67
78
  if (env.LOG_DATABASE_LEVELS) {
68
79
  levels = env.LOG_DATABASE_LEVELS
@@ -74,5 +85,5 @@ export function getDatabaseTransportConfigFromEnv(env: EnvLogConfig): { enabled:
74
85
  levels = ['warn', 'error'];
75
86
  }
76
87
 
77
- return { enabled, levels };
88
+ return { enabled, levels, appTag };
78
89
  }