Click here to Skip to main content
15,881,812 members
Articles / Desktop Programming / ATL
Article

A Simple Logging Utility in ATL

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
3 Jan 2000 95.1K   881   40   10
A simple logging utility to help debug your ATL applications
  • Download demo project - 48 Kb
  • You must have noticed that there are many occassions while developing an ATL component when you feel that you should trace some messages at some point. For such purpose, first thing which almost every one tries is ATLTRACE or ATLTRACE2 both of which Trace the messages to the debug output. That is perfect, but the problem is that you can trace only while you are in debug mode. You cannot trace anything while you are running the application. One option is to look for NT Event logger (if you are using Windows NT) But the problem is there are so many different events there that you feel like giving up. Moreever you need to learn the APIs used to write anything to NT Event Loggger. So I thought of developing a simple ATL component which you can use to log events. Remember this is just the first version. Based on feedback I am planning to enhance the logger and make some more functions available, like Saving the log to a database or file, sorting by time etc.

    The Sourcecode

    When you extract the zip file you will get three directories:

    • \ATLLogApp: This is the Log server. i.e it is responsible for logging events. If you want you can straightaway compile this DLL and then use it in your application. This DLL hosts one component CoLogger which exposes ICoLogger interface. It has following methods:

      Initialize()
      This should be called to initialize the server.
      Log([in] BSTR Message)
      Call this method to log the data.
      UnInitialize()
      This uninitializes the server.

    • \ATLClientForTracer: This is sample ATL client for the server which just forwards calls from MFC Client

    • \MFCClient: This is an MFC CLient which logs messages after every second. There is a timer which fires events .

    How to use.

    In you application(MFC or ATL) just type

    #import "..\ATLLogApp.tlb" no_namespace named_guids //specify the path to the tlb.

    and you will get two files .tlh and .tli in your source output directory (generally debug).Now to use it just delcare a smart pointer of type ICoLoggerPtr .e.g

    CYourclass : public ...
    {
    	ICoLoggerPtr m_Log;
    	...
    }

     

    in the cpp file creat the instance of the logger and then call Initialize

    // implemention file...
    const HRESULT hrCreate = m_Log.CreateInstance(__uuidof(CoLogger));
    if(FAILED(hrCreate)) return E_FAIL;
    const HRESULT hrInit = m_Log->Initialize();
    

    Now call the Log method on this interface wherever you want to.

    Here is a sample screen short when you run the application .

    Image 1

    Press Atl-S. You get this screen after some time.

    Image 2

    Any suggestions are welcome.

     

    Compilation Order:

    1. AtlLogApp
    2. AtlClientForTracer
    3. MFCClient.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Questiontime shown is wrong Pin
    debslab10-Mar-08 21:25
    debslab10-Mar-08 21:25 
    GeneralFile saving option in ATL DLL Pin
    Member 15355768-Dec-04 18:46
    Member 15355768-Dec-04 18:46 
    QuestionHow to call ATL EXE from ATL dll Pin
    Poojadpl12-Oct-04 3:08
    Poojadpl12-Oct-04 3:08 
    GeneralExcellent! Pin
    Wayzer19-Jan-02 7:36
    Wayzer19-Jan-02 7:36 
    GeneralATL DLL Problem Pin
    yamini8-Feb-01 21:45
    yamini8-Feb-01 21:45 
    GeneralATL DLL Problem Pin
    yamini8-Feb-01 21:43
    yamini8-Feb-01 21:43 
    Questiononly debug build is available ? Pin
    niv24-Aug-00 0:40
    niv24-Aug-00 0:40 
    Generalunable to create instance Pin
    Nitin Garg3-May-00 9:18
    Nitin Garg3-May-00 9:18 
    GeneralRe: unable to create instance Pin
    Clift Norris24-May-00 18:16
    Clift Norris24-May-00 18:16 
    GeneralGood Stuff Pin
    Aza Bajarne12-Apr-00 8:47
    Aza Bajarne12-Apr-00 8:47 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.