File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,19 +10,17 @@ import type { IsUndefined } from './types.ts'
1010
1111import major from 'semver/functions/major.js'
1212import valid from 'semver/functions/valid.js'
13+ import { logger } from './logger.ts'
1314
1415export class ProxyBus < E extends GenericEvents = NextcloudEvents >
1516implements EventBus < E > {
1617 private bus : EventBus < E >
1718
1819 constructor ( bus : EventBus < E > ) {
1920 if ( typeof bus . getVersion !== 'function' || ! valid ( bus . getVersion ( ) ) ) {
20- console . warn ( 'Proxying an event bus with an unknown or invalid version' )
21+ logger . warn ( 'Proxying an event bus with an unknown or invalid version' )
2122 } else if ( major ( bus . getVersion ( ) ) !== major ( this . getVersion ( ) ) ) {
22- console . warn ( 'Proxying an event bus of version '
23- + bus . getVersion ( )
24- + ' with '
25- + this . getVersion ( ) )
23+ logger . warn ( `Proxying an event bus of version ${ bus . getVersion ( ) } with ${ this . getVersion ( ) } ` )
2624 }
2725
2826 this . bus = bus
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import type { EventBus } from './EventBus.js'
88import type { EventHandler } from './EventHandler.js'
99import type { IsUndefined } from './types.ts'
1010
11+ import { logger } from './logger.ts'
12+
1113export class SimpleBus < E extends GenericEvents = NextcloudEvents >
1214implements EventBus < E > {
1315 private handlers = new Map < keyof E , EventHandler < E [ keyof E ] > [ ] > ( )
@@ -44,8 +46,8 @@ implements EventBus<E> {
4446 handlers . forEach ( ( h ) => {
4547 try {
4648 ( h as EventHandler < ( typeof event ) [ 0 ] > ) ( event [ 0 ] )
47- } catch ( e ) {
48- console . error ( 'could not invoke event listener' , e )
49+ } catch ( error ) {
50+ logger . error ( 'SimpleBus: Could not invoke event listener' , { error } )
4951 }
5052 } )
5153 }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import type { EventBus } from './EventBus.ts'
88import type { EventHandler } from './EventHandler.ts'
99import type { IsUndefined } from './types.ts'
1010
11+ import { logger } from './logger.ts'
1112import { ProxyBus } from './ProxyBus.ts'
1213import { SimpleBus } from './SimpleBus.ts'
1314
@@ -34,13 +35,13 @@ function getBus(): EventBus {
3435 // testing or SSR
3536 return new Proxy ( { } as EventBus , {
3637 get : ( ) => {
37- return ( ) => console . error ( 'Window not available, EventBus can not be established!' )
38+ return ( ) => logger . error ( 'Window not available, EventBus can not be established!' )
3839 } ,
3940 } )
4041 }
4142
4243 if ( window . OC ?. _eventBus && typeof window . _nc_event_bus === 'undefined' ) {
43- console . warn ( 'found old event bus instance at OC._eventBus. Update your version!' )
44+ logger . warn ( 'Found old event bus instance at OC._eventBus. Update your version!' )
4445 window . _nc_event_bus = window . OC . _eventBus
4546 }
4647
Original file line number Diff line number Diff line change 1+ /*!
2+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+ * SPDX-License-Identifier: GPL-3.0-or-later
4+ */
5+
6+ import { getLoggerBuilder } from '@nextcloud/logger'
7+
8+ export const logger = getLoggerBuilder ( )
9+ . setApp ( '@nextcloud/event-bus' )
10+ . build ( )
Original file line number Diff line number Diff line change 3737 "watch" : " npm run dev -- --watch"
3838 },
3939 "dependencies" : {
40+ "@nextcloud/logger" : " ^2.2.1" ,
4041 "@types/semver" : " ^7.7.0" ,
4142 "semver" : " ^7.7.2"
4243 },
You can’t perform that action at this time.
0 commit comments