![]() |
Platforms, Frameworks & Libraries »
ATL »
General
Intermediate
A Simple Logging Utility in ATLBy Ashish DharA simple logging utility to help debug your ATL applications |
VC6, ATL, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
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.
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() Log([in] BSTR Message) UnInitialize() \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 .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 .

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

Any suggestions are welcome.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 3 Jan 2000 Editor: Chris Maunder |
Copyright 2000 by Ashish Dhar Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |