Results 1 to 6 of 6

Thread: logger in a dll

  1. #1

    logger in a dll

    I'm using the logger unit in several dlls and in the main application, the problem is it initializes <log> upon loading.
    As all of the dlls are called from the same app they all want to create “myApp.log” (only the 1st one will win, and the rest won’t log)

    Any ideas for a clean nice fix?
    :arrow: Maybe if it fails add _# [size=9px](# = available number)[/size] to the app name, but then you don’t know the corresponding log for a dll.
    :arrow: Or we can remove the initialization part and do it our self, this will allow us to add any name we want.
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

  2. #2

    logger in a dll

    How about changing the initialization and finalization sections so they check if Log is nil and if yes then create it?

    [pascal]
    initialization
    begin
    if Log = nil then begin
    Log := TLogger.Create;
    Log.LogStatus( 'Starting Application', 'Initialization' );
    end;
    end;

    finalization
    begin
    if Log <> nil then begin
    Log.LogStatus( 'Terminating Application', 'Finalization' );
    Log.Free;
    Log := nil;
    end;
    end;
    [/pascal]
    I also like your second idea.

  3. #3

    logger in a dll

    I used the logger in 1 dll only and added an API to that dll

    Core_LogStatus
    Core_LogWarning
    Core_LogError


    all the other dll's and the main application use this API so they all write to the same log file.

    This works really well in my applications
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  4. #4

    logger in a dll

    grudzio: Your solution is completely wrong, you most likely get several AV, and even if you won’t you will still end up with one file. you’ll tell me why
    technomage: Best solution so far, but there is an advantage in having a log for each module you create...
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

  5. #5

    logger in a dll

    How about you overload the constructor of the TLogger class to take then name of the log file, if it's blank then user the ParamStr(0) filename.

    Or just give it a parameter with a default of EmptrStr


    [pascal]constructor TLogger.Create(ALogName: string = EmptyStr);[/pascal]
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  6. #6

    logger in a dll

    Quote Originally Posted by tanffn
    grudzio: Your solution is completely wrong, you most likely get several AV
    If the Log variable is defined like this
    Code:
    Log &#58; TLogger = nil;
    I dont see how can I get access violation.
    you will still end up with one file.
    I thought that is what you wanted to get. My mistake.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •