How to use Logog in MFC document multiple view?

48 views
Skip to first unread message

Ivan Timofeev

unread,
Oct 26, 2011, 3:49:28 PM10/26/11
to Logog
I am trying to use LOGOG system in an MFC document - multiple view
app. Now, it works well in CMainFrame class, however when i am trying
to use it in one of the subcalsses a System.AccessViolationException
happens.

I use LOGOG_INITIALIZE() in the CMainFrame constructor and
LOGOG_SHUTDOWN() in the destructor. In other class that started in
CMainFrame I decalare a class var pointer (or a method var no
pointer) m_pLogFile and in the constructor I populated it with new
LogFile("blah blah"). The accessViolation exception happens when i am
trying to log somthing with INFO(" Blah Blah") or with any other
macros.

Any suggestions how to use LOGOG in such app?

Thanks.

John Byrd

unread,
Oct 26, 2011, 4:05:10 PM10/26/11
to lo...@googlegroups.com
Does the crash still happen if you create another kind of output
instead, such as a logog::Cerr or logog::OutputDebug instead of a
LogFile ?

jwb

--
---

John Byrd
Gigantic Software
2102 Business Center Drive
Suite 144
Irvine, CA   92612-1001
http://www.giganticsoftware.com
T: (949) 892-3526 F: (206) 309-0850

John Byrd

unread,
Oct 26, 2011, 4:30:07 PM10/26/11
to lo...@googlegroups.com
Also, I'd love to see a screenshot of the callstack and the place where the exception occurs.  jwb

John Byrd

unread,
Oct 26, 2011, 4:40:06 PM10/26/11
to lo...@googlegroups.com
Lastly, note that I just fixed a bug having to do with how MFC and
debug mode treats the new() operator generally; make sure you have the
latest. jwb

Ivan Timofeev

unread,
Oct 26, 2011, 4:54:43 PM10/26/11
to Logog
It still happens with Cerr and OutputDebug. I have a CMainFrame where
I initialize Logog in the constructor; LOGOG_SHUTDOWN is in the d-tor.
In the CMainFrame::Login() I am using a method var logog::LogFile
myFile(FileName) and then INFO(blah blah).

After loggin-in, I open another window from the menu. In this class I
have a global var logog::LogFile* myLogFile. I populate it in the c-
tor and delete it in the d-tor. In OnInitDialog, I use the INFO and in
OnButton I use the INFO macros. The logog crashes here.

======================

The solution is to declare a class variable logog::LogFile m_pLogFile
in the CMainFrame class; declare LOGOG_INITIALIZE() in the c-tor,
populate m_pLogFile and delete m_pLogFile and run LOGOG_SHUTDOWN in
the d-tor. In windows that open from CMainFrame just use INFO and
other macros. They will log into the FileName file.

John Byrd

unread,
Oct 26, 2011, 5:11:50 PM10/26/11
to lo...@googlegroups.com
Weird. I wonder if maybe the classes are being created and the
LogFile instanced before CMainFrame::Login() gets to run. Anyway, I'm
glad you figured this one out. Let me know how it goes.

jwb

--

Ivan Timofeev

unread,
Oct 26, 2011, 5:17:29 PM10/26/11
to Logog
CMainFrame::CMainFrame()
{
LOGOG_INITIALIZE();
}

CMainFrame::Login()
{
logog::LogFile myLogFile("C:\\Temp\\myLogFile.log");
INFO("Blah-blah");
}

CMainFrame::~CMainFrame()
{
LOGOG_SHUTDOWN();
}

A window opens from a menu item in CMainFrame

Bool CSomeClass::OnInitDialog()
{
logog::LogFile myLogFile("C:\\Temp\\myLogFile.log");
INFO("Some blah-blah"); <--- Here it will crash.
}

at that spot:

while ( it != m_Subscribers.end() )
{
pCurrentNode = *it;

CRASH------------------> if ( pCurrentNode->IsTopic() == false )
continue;

pCurrentTopic = ( Topic * )pCurrentNode;

m_Subscribers.MutexUnlock();

if ( pCurrentTopic )
nError += pCurrentTopic->Receive( node );

m_Subscribers.MutexLock();
it++;
}

Call Stack (fragment)

> MVSS.exe!logog::Topic::Send(const logog::Topic & node={...}) Line 95 + 0xf bytes C++
MVSS.exe!logog::Topic::Receive(const logog::Topic & node={...})
Line 122 + 0x13 bytes C++
MVSS.exe!logog::Topic::Send(const logog::Topic & node={...}) Line
103 + 0x13 bytes C++
MVSS.exe!logog::Checkpoint::Send(const logog::Topic & node={...})
Line 28 C++
MVSS.exe!logog::Topic::Transmit() Line 116 + 0x13 bytes C++
[Managed to Native Transition]
MVSS.exe!CPumpManualCtrl::OnInitDialog() Line 59 + 0x12e bytes C++
[Native to Managed Transition]
mfc90ud.dll!AfxDlgProc(HWND__ * hWnd=0x00600a10, unsigned int
message=272, unsigned int __formal=1706392, unsigned int
__formal=1706392) Line 28 + 0x10 bytes C++

Ivan Timofeev

unread,
Oct 26, 2011, 5:26:18 PM10/26/11
to Logog
it can be reporoduced with a simple doc-view MFC demo app.

John Byrd

unread,
Oct 26, 2011, 6:32:37 PM10/26/11
to lo...@googlegroups.com
Oh, I see what's going on then. You really ought to have only one
LogFile for a specific output file instanced anywhere in your app. It
only needs to be called once per process -- you don't need two LogFile
objects, I think.

jwb

--

Ivan Timofeev

unread,
Oct 27, 2011, 11:26:01 AM10/27/11
to Logog
I thought when the control goes out of the scope the object is
destroyed and file reset and I could declare a new object. It does not
work like that?

CMainFrame::Login()
{
LogFile myLogFile("FileName")
WARN("Blah");
}

I would not be able to declare another LogFile var in another class?
If I use a different name? I have to call LOGOG_SHUTDOWN() before i
can do that?

John Byrd

unread,
Oct 27, 2011, 1:18:18 PM10/27/11
to lo...@googlegroups.com
Yes, what you're describing is basically correct -- you can have as
many LogFiles as you want; however, by your example, you gave the same
name to both LogFile objects. I think it should be OK to do what
you're describing if you give different file names to different
LogFile objects. Otherwise there's no need to declare multiple
LogFiles.

Are you trying to log all the objects in one class into one file, and
objects in another class into another file? If that's the case, then
you'll need a Filter and a LogFile per class, in addition to using the
LOGOG_CATEGORY to represent each of your classes. See
http://johnwbyrd.github.com/logog/multipletargets.html if that's the
case... and make sure to UnpublishToMultiple( AllTargets() ) function
on each of the Filters.

jwb

> --
> You received this message because you are subscribed to the Google Groups "Logog" group.
> To post to this group, send email to lo...@googlegroups.com.
> To unsubscribe from this group, send email to logog+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/logog?hl=en.

John Byrd

unread,
Oct 27, 2011, 1:19:37 PM10/27/11
to lo...@googlegroups.com
Lastly, it sounds as if you were able to create a crash using a small
test program, if you accomplished this I'd appreciate if you would zip
up the test project and email to me so I can replicate. Thanks.

jwb

Ivan Timofeev

unread,
Oct 27, 2011, 5:09:31 PM10/27/11
to Logog
I was not using Logog correctly, just learning curve.

Logog is one of the best open source logging system now. Great
customer support too!

Thanks!!!
Reply all
Reply to author
Forward
0 new messages