mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-12-25 11:20:18 +00:00
* crawl state: add getPendingList() to return pending state from either memory or redis crawl state, fix stats logging with redis state. Return pending list as json object logging: check if data object is an error, log fields from error. Convert missing console.* to new logger * evaluate failuire: log with error, not fatal
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
// ===========================================================================
|
|
|
|
export class Logger
|
|
{
|
|
constructor(debugLogging=false) {
|
|
this.debugLogging = debugLogging;
|
|
}
|
|
|
|
logAsJSON(message, data, context, logLevel="info") {
|
|
if (data instanceof Error) {
|
|
data = {"type": "exception", "message": data.message, "stack": data.stack};
|
|
} else if (typeof data !== "object") {
|
|
data = {"message": data.toString()};
|
|
}
|
|
let dataToLog = {
|
|
"logLevel": logLevel,
|
|
"timestamp": new Date().toISOString(),
|
|
"context": context,
|
|
"message": message,
|
|
"details": data ? data : {}
|
|
};
|
|
console.log(JSON.stringify(dataToLog));
|
|
}
|
|
|
|
info(message, data={}, context="general") {
|
|
this.logAsJSON(message, data, context);
|
|
}
|
|
|
|
error(message, data={}, context="general") {
|
|
this.logAsJSON(message, data, context, "error");
|
|
}
|
|
|
|
warn(message, data={}, context="general") {
|
|
this.logAsJSON(message, data, context, "warn");
|
|
}
|
|
|
|
debug(message, data={}, context="general") {
|
|
if (this.debugLogging) {
|
|
this.logAsJSON(message, data, context, "debug");
|
|
}
|
|
}
|
|
|
|
fatal(message, data={}, context="general", exitCode=1) {
|
|
this.logAsJSON(`${message}. Quitting`, data, context, "fatal");
|
|
process.exit(exitCode);
|
|
}
|
|
}
|