On Tuesday, 13 August 2013 at 16:10:19 UTC, Marek Janukowicz wrote:
I implemented some generic logging module and want to use single Logger
object per module. Some simplified excerpt from my code:

module log;
mixin template makeLogger( params,,, name ) {
  Logger logger;
  static this () {
  .. logger initialization...
  }
}

-------------

module another;
import log;

mixin makeLogger!( ...., __MODULE__ );
logger( DEBUG, "aksjfakjdf" );

-------------

module yet_another;
import log;

mixin makeLogger!( ...., __MODULE__ );
logger( INFO, "sdfsdfsdf" );

This works quite well, but if I import one module into another I get an obvious name clash on the variable name "logger". I have many modules where I want to use logging, so things like static import are not an option.

Is there any pattern I could use here?

is it necessary use multiple loggers? maybe you should move ur Logger instance to module scope(log module) and just handle log sources some other way(i.e. add source string mapping in log module)? because i mean this clash is just due to multiple instantions of this template

Reply via email to