@gratheon/log-lib 2.2.4 → 2.2.6
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.
- package/README.md +6 -1
- package/dist/logger.js +17 -0
- package/package.json +1 -1
- package/src/logger.ts +16 -0
package/README.md
CHANGED
|
@@ -32,7 +32,12 @@ npm install @gratheon/log-lib
|
|
|
32
32
|
|
|
33
33
|
The logger automatically creates the database and table on first initialization. No manual setup required!
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
**Automatic Migrations**: When updating from older versions, the logger automatically runs migrations on initialization:
|
|
36
|
+
- Checks if the `stacktrace` column exists
|
|
37
|
+
- Adds it if missing (for v2.2.0+ compatibility)
|
|
38
|
+
- Non-blocking: app starts even if migration fails
|
|
39
|
+
|
|
40
|
+
For reference, migration scripts are available in the `migrations/` directory.
|
|
36
41
|
|
|
37
42
|
## Usage
|
|
38
43
|
|
package/dist/logger.js
CHANGED
|
@@ -107,7 +107,24 @@ async function initializeConnection(config) {
|
|
|
107
107
|
INDEX idx_level (level)
|
|
108
108
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
109
109
|
`);
|
|
110
|
+
// Run migrations: Add stacktrace column if it doesn't exist (for existing tables created before v2.2.0)
|
|
111
|
+
try {
|
|
112
|
+
const columns = await conn.query((0, mysql_1.sql) `SHOW COLUMNS FROM \`logs\` LIKE 'stacktrace'`);
|
|
113
|
+
if (columns.length === 0) {
|
|
114
|
+
console.log('[log-lib] Running migration: Adding stacktrace column...');
|
|
115
|
+
await conn.query((0, mysql_1.sql) `ALTER TABLE \`logs\` ADD COLUMN \`stacktrace\` TEXT AFTER \`meta\``);
|
|
116
|
+
console.log('[log-lib] Migration complete: stacktrace column added');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log('[log-lib] Migration check: stacktrace column already exists');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (migrationErr) {
|
|
123
|
+
console.error('[log-lib] Migration failed (non-critical):', migrationErr);
|
|
124
|
+
// Don't fail initialization if migration fails
|
|
125
|
+
}
|
|
110
126
|
dbInitialized = true;
|
|
127
|
+
console.log('[log-lib] Database initialization complete');
|
|
111
128
|
}
|
|
112
129
|
catch (err) {
|
|
113
130
|
console.error('Failed to initialize logs database:', err);
|
package/package.json
CHANGED
package/src/logger.ts
CHANGED
|
@@ -91,7 +91,23 @@ async function initializeConnection(config: LoggerConfig) {
|
|
|
91
91
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
92
92
|
`);
|
|
93
93
|
|
|
94
|
+
// Run migrations: Add stacktrace column if it doesn't exist (for existing tables created before v2.2.0)
|
|
95
|
+
try {
|
|
96
|
+
const columns = await conn.query(sql`SHOW COLUMNS FROM \`logs\` LIKE 'stacktrace'`);
|
|
97
|
+
if (columns.length === 0) {
|
|
98
|
+
console.log('[log-lib] Running migration: Adding stacktrace column...');
|
|
99
|
+
await conn.query(sql`ALTER TABLE \`logs\` ADD COLUMN \`stacktrace\` TEXT AFTER \`meta\``);
|
|
100
|
+
console.log('[log-lib] Migration complete: stacktrace column added');
|
|
101
|
+
} else {
|
|
102
|
+
console.log('[log-lib] Migration check: stacktrace column already exists');
|
|
103
|
+
}
|
|
104
|
+
} catch (migrationErr) {
|
|
105
|
+
console.error('[log-lib] Migration failed (non-critical):', migrationErr);
|
|
106
|
+
// Don't fail initialization if migration fails
|
|
107
|
+
}
|
|
108
|
+
|
|
94
109
|
dbInitialized = true;
|
|
110
|
+
console.log('[log-lib] Database initialization complete');
|
|
95
111
|
} catch (err) {
|
|
96
112
|
console.error('Failed to initialize logs database:', err);
|
|
97
113
|
// Don't throw - allow the service to start even if logging DB fails
|