bigquery-client
Version:
A feature-rich Node.js client for Google BigQuery with support for CRUD operations, transactions, query building, and advanced features like aggregate functions, pagination, and logging.
52 lines (51 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const constants_1 = require("../../config/constants");
class Logger {
constructor(enabled = true) {
this.logEntries = [];
this.enabled = enabled;
this.maxEntries = constants_1.DEFAULT_LOGGING_CONFIG.maxEntries;
this.level = constants_1.DEFAULT_LOGGING_CONFIG.level;
}
log(entry) {
if (!this.enabled)
return;
this.logEntries.push(entry);
if (this.logEntries.length > this.maxEntries) {
this.logEntries.shift();
}
// Implement your logging logic here (e.g., console, file, or external service)
console.log(`[${entry.level}] ${entry.timestamp}: ${entry.query}`);
if (entry.error) {
console.error(entry.error);
}
}
logQuery(query, params) {
this.log({
timestamp: new Date().toISOString(),
level: 'info',
query,
params: params || [],
executionTime: 0
});
}
logError(error) {
this.log({
timestamp: new Date().toISOString(),
level: 'error',
query: '',
params: [],
executionTime: 0,
error
});
}
getLogs() {
return this.logEntries;
}
clearLogs() {
this.logEntries = [];
}
}
exports.Logger = Logger;