Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger in New Platform should expose a factory method #39695

Closed
mshustov opened this issue Jun 26, 2019 · 1 comment · Fixed by #52605
Closed

Logger in New Platform should expose a factory method #39695

mshustov opened this issue Jun 26, 2019 · 1 comment · Fixed by #52605
Assignees
Labels
chore Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@mshustov
Copy link
Contributor

mshustov commented Jun 26, 2019

In the New platform, LoggerFactory can create Logger, but Logger cannot create a new Logger that extend parents context.
When you want to create several loggers in one context you either have to pass several different Logger instances or pass both Logger and LoggerFactory deeper to a children tree and repeat the whole list of context paths down the tree.

class Service/Plugin {
  constructor(private core: CoreContext){
    this.log = core.logger.get('service-name');
  }
  setup(){
    this.log.info('starting...'); // ['service-name']: starting
    new ServiceA(this.core.logger).setup()
  }

class ServiceA {
  constructor(private logger: LoggerFactory){
    this.log = logger.get('service-name', 'service-a') // knows in what context it was created
  }
  setup(){
    this.log.info('stating') // ['service-name', 'service-a']: starting...
    new ServiceB(logger.get('service-name', 'service-a', 'service-b'))
  }
}

// what if ServiceC wants to use ServiceA as well?
class ServiceA {
  constructor(private log, private logger: LoggerFactory){}
  setup(){
    this.log.info('stating') // ['service-name', 'service-a']: starting...
    new ServiceB(logger.get('service-b')) // now Service B doesn't know in what context it was created
  }
}

To solve the problem we can extend Logger to provide a Factory method that creates new logger bound to a parent context. Something like:

get(...contextPaths) => new Logger(...this.contextPaths,...contextPaths);
@mshustov mshustov added chore Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform labels Jun 26, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants