Simple Logging Utilily in ATL

You must have noticed that many 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 on debug output,That is perfect.But 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 the input I am planning to enhance the logger and make some more functions available like Saving of log to a database or file.Sorting by time etc.

Following is the description about the source code given here

SourceCode.zip

When you extract this zip file you will get three directories.For example if you extract the zip file into c:\code, you will get c:\Code\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 you 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.

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

c:\Code\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 the following


#import "..\ATLLogApp.tlb" no_namespace named_guids // specify the path to the tlb
You will then get two files .tlh and .tli in your source output directory (by default, this will be the debug directory). Now to use it just declare a smart pointer of type ICoLoggerPtr as in this example.


CYourclass:public ...
{
 ICoLoggerPtr m_Log;
 ...
}
in the cpp file create 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.

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

Any suggestions are welcome.

Compilation Order

  • AtlLogApp
  • AtlClientForTracer
  • MFCClient
  • Downloads

    Download source - 48 Kb


    Comments

    • There are no comments yet. Be the first to comment!

    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

    • Ever-increasing workloads and the challenge of containing costs leave companies conflicted by the need for increased processing capacity while limiting physical expansion. Migration to HP's new generation of increased-density rack-and-blade servers can address growing demands for compute capacity while reducing costly sprawl. Sponsored by: HP and Intel® Xeon® processors Intel, the Intel logo, and Xeon Inside are trademarks of Intel Corporation in the U.S. and/or other countries. HP is the sponsor …

    Most Popular Programming Stories

    More for Developers

    Latest Developer Headlines

    RSS Feeds