UNPKG

log-mate

Version:

log-mate makes logging effortless & powerful—log to console, files, databases, or cloud with structured logs, encryption, real-time streaming, and auto-rotation. It’s plug & play, supports multi-transport logging, and boosts performance with async, lazy l

14 lines (11 loc) 443 B
const mysql = require("mysql2/promise"); async function toDatabase(dbConfig) { const connection = await mysql.createConnection(dbConfig); return async (level, message, ...args) => { await connection.execute( "INSERT INTO logs (level, message, timestamp) VALUES (?, ?, ?)", [level, `${message} ${args.join(" ")}`, new Date().toISOString()] ); }; } module.exports = toDatabase;