Skip to content

Commit 0e8e5ed

Browse files
committed
Feat: Begin implementing logging
1 parent 867b945 commit 0e8e5ed

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

packages/query/src/behavior.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,48 @@ export class Behavior {
529529
return found ?? undefined;
530530
}
531531

532+
// Helper method for log level checking
533+
canLog(requiredLevel) {
534+
const levels = ['silent', 'error', 'warn', 'info', 'debug'];
535+
const currentLevel = levels.indexOf(this.settings.logLevel || 'silent');
536+
const required = levels.indexOf(requiredLevel);
537+
return currentLevel >= required;
538+
}
539+
540+
outputLog(level, consoleMethod, color, message, data) {
541+
if (!this.canLog(level)) { return; }
542+
543+
const args = [`%c[${this.namespace}]%c ${message}`, `color: ${color}; font-weight: bold;`, 'color: inherit;'];
544+
if (data !== undefined) {
545+
args.push(data);
546+
}
547+
548+
console[consoleMethod](...args);
549+
}
550+
551+
log(message, data) {
552+
this.outputLog('info', 'log', '#0066cc', message, data);
553+
}
554+
555+
debug(message, data) {
556+
this.outputLog('debug', 'debug', '#666', message, data);
557+
}
558+
559+
warn(message, data) {
560+
this.outputLog('warn', 'warn', '#ff9800', message, data);
561+
}
562+
563+
error(message, data) {
564+
this.outputLog('error', 'error', '#f44336', message, data);
565+
566+
// Optional: dispatch error event for handling
567+
this.dispatchEvent('behavior:error', {
568+
message,
569+
namespace: this.namespace,
570+
data,
571+
});
572+
}
573+
532574
// Get or set individual setting
533575
setting(name, value) {
534576
if (value === undefined) {
@@ -566,6 +608,12 @@ export class Behavior {
566608
dispatchEvent: self.dispatchEvent.bind(this),
567609
dispatchGroupEvent: self.dispatchGroupEvent.bind(this),
568610

611+
// Add logging functions
612+
log: self.log.bind(self),
613+
debug: self.debug.bind(self),
614+
warn: self.warn.bind(self),
615+
error: self.error.bind(self),
616+
569617
// element index information
570618
index: self.elementIndex,
571619
total: self.totalElements,

src/behaviors/transition/transition.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ const createBehavior = (
5959
isFirst,
6060
isLast,
6161
total,
62+
log,
63+
warn,
64+
error,
6265
},
6366
) => ({
6467
initialize() {
@@ -74,16 +77,20 @@ const createBehavior = (
7477
...runtimeSettings,
7578
};
7679

80+
log('Starting animation', { animation: animationSettings.animation });
81+
7782
// handle case of already animating
7883
// handle animation queuing
7984
if (self.isAnimating()) {
8085
if (settings.queue) {
86+
log('Animation already running, queuing');
8187
const eventName = (el.animatingGroup)
8288
? 'transition:groupEnd'
8389
: 'transition:end';
8490
await $(el).onNext(eventName);
8591
}
8692
else {
93+
warn('Animation already running, stopping previous');
8794
self.stop();
8895
}
8996
}
@@ -250,7 +257,7 @@ const createBehavior = (
250257
// takes a set of css animations and then performs them using web animation API
251258
async performAnimation(cssAnimations, direction, { duration, callback = noop, delay } = {}) {
252259
if (!cssAnimations || !cssAnimations.exists) {
253-
console.warn('No animation data available for', cssAnimations.name);
260+
warn('No animation data available for', cssAnimations.name);
254261
return;
255262
}
256263

0 commit comments

Comments
 (0)