Skip to content

Commit b966448

Browse files
authored
more logging tweaks: (#94)
* more logging tweaks: - ensure all logging from site-specific behaviors are wrapped with siteSpecific: true - if yield returns null, don't log anything (may be logged elsewhere already) - more log -> debug to reduce logging clutter - bump to 0.8.4
1 parent e6ef780 commit b966448

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browsertrix-behaviors",
3-
"version": "0.8.3",
3+
"version": "0.8.4",
44
"main": "index.js",
55
"author": "Webrecorder Software",
66
"license": "AGPL-3.0-or-later",

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class BehaviorManager {
132132
for (const name in this.loadedBehaviors) {
133133
const siteBehaviorClass = this.loadedBehaviors[name];
134134
if (siteBehaviorClass.isMatch()) {
135-
behaviorLog({msg: "Using Site-Specific Behavior: " + name, siteSpecific: true});
135+
behaviorLog("Using Site-Specific Behavior: " + name);
136136
this.mainBehaviorClass = siteBehaviorClass;
137137
const siteSpecificOpts = typeof opts.siteSpecific === "object" ?
138138
(opts.siteSpecific[name] || {}) : {};
@@ -210,6 +210,7 @@ export class BehaviorManager {
210210
async awaitPageLoad() {
211211
this.selectMainBehavior();
212212
if (this.mainBehavior?.awaitPageLoad) {
213+
behaviorLog("Waiting for custom page load via behavior");
213214
await this.mainBehavior.awaitPageLoad();
214215
}
215216
}

src/lib/behavior.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export class BackgroundBehavior {
1111
behaviorLog(msg, "error");
1212
}
1313

14-
log(msg) {
15-
behaviorLog(msg, "info");
14+
log(msg, type = "info") {
15+
behaviorLog(msg, type);
1616
}
1717
}
1818

@@ -155,7 +155,8 @@ export class BehaviorRunner extends BackgroundBehavior {
155155
let {state, opts} = behavior.init();
156156
state = state || {};
157157
opts = opts ? {...opts, ...mainOpts} : mainOpts;
158-
const log = behaviorLog;
158+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
159+
const log = async (data: any, type: string) => this.wrappedLog(data, type);
159160

160161
this.ctx = { Lib, state, opts, log };
161162

@@ -164,6 +165,17 @@ export class BehaviorRunner extends BackgroundBehavior {
164165
this._unpause = null;
165166
}
166167

168+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
169+
wrappedLog(data: any, type = "info") {
170+
let logData;
171+
if (typeof data === "string" || data instanceof String) {
172+
logData = {msg: data}
173+
} else {
174+
logData = data;
175+
}
176+
this.log({...logData, behavior: this.behaviorProps.id, siteSpecific: true}, type);
177+
}
178+
167179
start() {
168180
this._running = this.run();
169181
}
@@ -175,20 +187,16 @@ export class BehaviorRunner extends BackgroundBehavior {
175187
async run() {
176188
try {
177189
for await (const step of this.inst.run(this.ctx)) {
178-
let logStep;
179-
if (typeof step === "string" || step instanceof String) {
180-
logStep = {msg: step}
181-
} else {
182-
logStep = step;
190+
if (step) {
191+
this.wrappedLog(step);
183192
}
184-
this.log({...logStep, behavior: this.behaviorProps.id, siteSpecific: true});
185193
if (this.paused) {
186194
await this.paused;
187195
}
188196
}
189-
this.log({msg: "done!", behavior: this.behaviorProps.id, siteSpecific: true});
197+
this.debug({msg: "done!", behavior: this.behaviorProps.id});
190198
} catch (e) {
191-
this.error({msg: e.toString(), behavior: this.behaviorProps.id, siteSpecific: true});
199+
this.error({msg: e.toString(), behavior: this.behaviorProps.id});
192200
}
193201
}
194202

0 commit comments

Comments
 (0)