Namespace clash between modules

Marek Janukowicz marek at janukowicz.net
Tue Aug 13 09:11:42 PDT 2013


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?

-- 
Marek Janukowicz


More information about the Digitalmars-d-learn mailing list