import { Observable , Subscription } from 'rxjs' ; import { Logger } from '@osd/logging' ; import { CoreService } from '../../types' ; import { LoggingConfig , LoggerContextConfigInput } from './logging_config' ; import { ILoggingSystem } from './logging_system' ; import { CoreContext } from '../core_context' ; public export interface LoggingServiceSetup { remarks example param config$ configure ( config$ ) : void ; } internal export interface InternalLoggingServiceSetup { configure ( contextParts , config$ ) : void ; } interface SetupDeps { loggingSystem : ILoggingSystem ; } internal export class LoggingService implements CoreService < InternalLoggingServiceSetup > { private readonly subscriptions = new Map < string , Subscription > ( ) ; private readonly log : Logger ; constructor ( coreContext ) { this . log = coreContext . logger . get ( 'logging' ) ; } public setup ( { loggingSystem } ) { return { configure : ( contextParts , config$ ) => { const contextName = LoggingConfig . getLoggerContext ( contextParts ) ; this . log . debug ( `Setting custom config for context [${ contextName }]` ) ; const existingSubscription = this . subscriptions . get ( contextName ) ; if ( existingSubscription ) { existingSubscription . unsubscribe ( ) ; } this . subscriptions . set ( contextName , config$ . subscribe ( ( config ) => { this . log . debug ( `Updating logging config for context [${ contextName }]` ) ; loggingSystem . setContextConfig ( contextParts , config ) ; } ) ) ; } , } ; } public start ( ) { } public stop ( ) { for ( const [ , subscription ] of this . subscriptions ) { subscription . unsubscribe ( ) ; } } }