xp-framework/logging

Replace singleton Logger

Closed this issue · 1 comments

The util.log.Logger class should be replaced by a new API simplifying setup code.

Here are some ideas:

  • Configurable via ini file (like the old logger, but more elegant syntax) and/or programmatically via fluent interface
  • Can define policies (in form of an interface, which users can implement) to steer what is logged where
  • ...
$logging= (new Logging())
  ->in((new ServerMode('prod'))
    ->log()->to(new FileAppender('application.log'))         // Default category
    ->log('sql')->to(new FileAppender('sql.log'))
    ->using(new ErrorsOnly())
  )
  ->log('default')->to(new ConsoleAppender())
;
$logging->category()->info('Starting application');

_:warning: Work in progress_

Implemented by #6

public abstract class util.log.Logging {
  public static util.log.LogSetup all()
  public static util.log.LogSetup named(string $category)
  public static util.log.LogSetup of(int $level)
  public static util.log.LogSetup using(util.log.Layout $layout)
}