On Sunday, 10 April 2016 at 18:26:57 UTC, Suliman wrote:
Sorry for wrong posting!

I have got logger instance in App.d

void main()
{
...
 FileLogger fLogger = new FileLogger("ErrorLog.txt");
 foo();
}

utils.d:
foo()
{
// I need logging here
}

Also I have file utils.d that include stand-alone functions that is not in classes. In one of them I need to implement logging.

What is the best way to do it. I see only two way -- create new Loggining instance. And second -- to import App.d as module, because without importing I would not able to see Logger instance.

But both of this way is look ugly. Is there any best solution?

You could pass an argument of type FileLogger (probably better a pointer?)
foo ( FileLogger log )
{ }

Other whay is to leave FileLogger instance in a separated module:
logger.d
public static FileLogger fLogger;

App.d
import logger; //the module
void main()
{
    // generate instance
    logger = new FileLogger("ErrorLog.txt");
}

utils.d
import logger; // the module

foo ()
{
    fLogger...
}

I cannot think in other ways.

JV

Reply via email to