@@ -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 ,
0 commit comments