Hi Norbert

2016-04-27 10:43 GMT+02:00 Norbert Hartl <norb...@hartl.name>:

> So assuming the Log class would not contain log levels but SysLog would do
> you could easily override #logClass in your domain object and use it this
> way
>
> MyDomainClass class>>#logClass
> ^ SysLog
>
> myDomainObject asLog
> warning;
> emit
>
> This way we do not need to pollute Object with a lot of methods that are
> tight to one use case. The call to #warning could be something else that
> only depends on the Log class you want to use.
>

There is one problem with this approach when we split preparation and
emitting of log object. It will always produce garbage. If no logs will
have interest in myDomainObject or #warning-level messages application will
continue create log entries.
I think it is important to minimize cost of logging when nobody have
interest on particular event. If debug-level log is disabled then no
garbage should be created. If stack traces log is disabled then no stack
information should be retrieved anywhere.
To achieve this we should create log entry instances only when we will find
any logs for them. It imposes restriction on possible API. At point when we
are ready to log something we should have all information which can be part
of filter. So if we want to filter logs by domain objects and log-levels we
need both parameters in one message send. Then we can ask every registered
log for interest about both of them. And only when we will find any one we
will create log entry instance for them.

Reply via email to