@gratheon/log-lib 2.2.4 → 2.2.5
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 +13 -0
- package/package.json +1 -1
- package/src/logger.ts +13 -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,6 +107,19 @@ 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)
|
|
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
|
+
}
|
|
119
|
+
catch (migrationErr) {
|
|
120
|
+
console.error('[log-lib] Migration failed (non-critical):', migrationErr);
|
|
121
|
+
// Don't fail initialization if migration fails
|
|
122
|
+
}
|
|
110
123
|
dbInitialized = true;
|
|
111
124
|
}
|
|
112
125
|
catch (err) {
|
package/package.json
CHANGED
package/src/logger.ts
CHANGED
|
@@ -91,6 +91,19 @@ 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)
|
|
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
|
+
}
|
|
102
|
+
} catch (migrationErr) {
|
|
103
|
+
console.error('[log-lib] Migration failed (non-critical):', migrationErr);
|
|
104
|
+
// Don't fail initialization if migration fails
|
|
105
|
+
}
|
|
106
|
+
|
|
94
107
|
dbInitialized = true;
|
|
95
108
|
} catch (err) {
|
|
96
109
|
console.error('Failed to initialize logs database:', err);
|