mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 06:23:16 +00:00
behavior logging:
- add 'behaviorScriptCustom' log context if siteSpecific is set - move 'msg' to main message field if present in behavior log object
This commit is contained in:
parent
bf6fbe8776
commit
4d2e6d9934
2 changed files with 19 additions and 8 deletions
|
@ -32,7 +32,7 @@ import {
|
|||
import { ScreenCaster, WSTransport } from "./util/screencaster.js";
|
||||
import { Screenshots } from "./util/screenshots.js";
|
||||
import { initRedis } from "./util/redis.js";
|
||||
import { logger, formatErr, LogDetails } from "./util/logger.js";
|
||||
import { logger, formatErr, LogDetails, LogContext } from "./util/logger.js";
|
||||
import { WorkerState, closeWorkers, runWorkers } from "./util/worker.js";
|
||||
import { sleep, timedRun, secondsElapsed } from "./util/timing.js";
|
||||
import { collectCustomBehaviors, getInfoString } from "./util/file_reader.js";
|
||||
|
@ -645,33 +645,43 @@ export class Crawler {
|
|||
|
||||
const logDetails = { page: pageUrl, workerid };
|
||||
|
||||
let context: LogContext = "behaviorScript";
|
||||
|
||||
if (typeof data === "string") {
|
||||
message = data;
|
||||
details = logDetails;
|
||||
} else {
|
||||
message = type === "info" ? "Behavior log" : "Behavior debug";
|
||||
details =
|
||||
typeof data === "object"
|
||||
? { ...(data as object), ...logDetails }
|
||||
: logDetails;
|
||||
if (typeof data === "object") {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const objData = data as any;
|
||||
if (objData.siteSpecific) {
|
||||
context = "behaviorScriptCustom";
|
||||
}
|
||||
message = objData.msg || message;
|
||||
delete objData.msg;
|
||||
details = { ...objData, ...logDetails };
|
||||
} else {
|
||||
details = logDetails;
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case "info":
|
||||
behaviorLine = JSON.stringify(data);
|
||||
if (behaviorLine !== this.behaviorLastLine) {
|
||||
logger.info(message, details, "behaviorScript");
|
||||
logger.info(message, details, context);
|
||||
this.behaviorLastLine = behaviorLine;
|
||||
}
|
||||
break;
|
||||
|
||||
case "error":
|
||||
logger.error(message, details, "behaviorScript");
|
||||
logger.error(message, details, context);
|
||||
break;
|
||||
|
||||
case "debug":
|
||||
default:
|
||||
logger.debug(message, details, "behaviorScript");
|
||||
logger.debug(message, details, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ export const LOG_CONTEXT_TYPES = [
|
|||
"blocking",
|
||||
"behavior",
|
||||
"behaviorScript",
|
||||
"behaviorScriptCustom",
|
||||
"jsError",
|
||||
"fetch",
|
||||
"pageStatus",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue