What is best way to get see function from separate file

Jonathan Villa via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 10 14:55:38 PDT 2016


On Sunday, 10 April 2016 at 18:57:45 UTC, Suliman wrote:
>
> I like it. Am i right understand that it prevent creation 
> unneeded of new instance of logger?


No, you need to pass a valid instance in foo(...), It should have 
been created before the call to foo(...).

I prefer the second way (separate file of the fLogger variable) 
so you can use any time, everywhere just adding the import using 
just one instance.

If you want create an instance every time you get to foo() and 
without the need of an argument, just import the logger library:

import std.experimental.logger; //here
foo()
{
     auto log = new FileLogger("ErrorLog.txt");
     ...
     destroy(log);
}

>
> And what problems I can get if I will create new instance of 
> logger in every stand alone function? Just resource overusage?

I don't know how exactly FileLogger works, if it need some kind 
of close() function like normal files or it open the file ... 
write on it ... and after that it close the file.
But the basic thing is ... yes, allocatin and deallocating an 
instance everytime you are going to use it.

JV.


More information about the Digitalmars-d-learn mailing list