Feature request: Easier work with LOGOG_INITIALIZE(), LOGOG_SHUTDOWN()

65 views
Skip to first unread message

Egor Samosvat

unread,
Oct 23, 2012, 4:04:29 AM10/23/12
to lo...@googlegroups.com
Hi, we have an idea and the problem.

1. Idea

We made the following wrapper class to automatically call LOGOG_INITIALIZE() and LOGOG_SHUTDOWN().

   9   class Log {
  10   public:
  11     typedef boost::shared_ptr<logog::Target> TargetPtr;
  12
  13     Log() {
  14       LOGOG_INITIALIZE();
  15       target_ = TargetPtr(new logog::Cout);
  16       logog::GetDefaultFormatter().SetShowTimeOfDay(true);
  17     }
  18     Log(const char* filename) {
  19       LOGOG_INITIALIZE();
  20       target_ = TargetPtr(new logog::LogFile(filename));
  21       logog::GetDefaultFormatter().SetShowTimeOfDay(true);
  22     }
  23     void setTargetAsFile(const char* filename) {
  24       target_ = TargetPtr(new logog::LogFile(filename));
  25     }
  26     void setTargetAsCout() {
  27       target_ = TargetPtr(new logog::Cout);
  28     }
  29     ~Log() {
  30       target_.reset();
  31       LOGOG_SHUTDOWN();
  32     }
  33   private:
  34     TargetPtr target_;
  35   };

So, for us it seems like an easier and more natural way to work with LOGOG.

void main () {
   Log log;
   INFO("Info");
}

2. Problem

Then we wanted to make things even easier and have just one global static object of this class.

static Log log;

Thus user could completely forget about LOGOG_INITIALIZE() and LOGOG_SHUTDOWN().

It's really important for us as LOGOG is just part of our own library
and we don't want to bother user with studying of two libraries.

But we faced the following problem

Unhandled exception at 0x77408da9 (ntdll.dll) in ltr_test.exe: 0xC0000005: Access violation writing location 0x00000014.
at logog\src\mutex.cpp:34 during initialization

Actually for us it is sufficient if LOGOG will have some "behaviour by default"
when LOGOG_INITIALIZE() wasn't called.


Can you adopt our solution or may be you have your own?

John Byrd

unread,
Oct 23, 2012, 12:43:24 PM10/23/12
to lo...@googlegroups.com
Thanks for writing in Egor.  Let me give my thoughts on this issue and how it might be worked around.

First off, it seems to me that you're not advocating for removing initialization entirely; you're advocating for moving it into a static initializer which would be called before main().  logog allocates a small amount of memory at LOGOG_INITIALIZATION() time; specifically, it sets up memory management and allocates a default Filter using that memory management.  I did this specifically to try to make logog avoid static initialization; in fact, logog would have been much easier to design had I permitted it to use static initializers.  (The rlog library makes heavy use of static initializers, which can end up stealing a great deal of memory before main() is called.)  

This is all just a caution to you that some users consider "secret" static initializers to be a major source of headaches.

However, I don't think that this is necessarily the source of your crash.  Without having access to your code I suspect the s_mInitialization mutex in api.cpp.  If you have time, remove all references to it from api.cpp and see if your problem goes away.  Alternately, you can wait until I have time to set up a test case based on the problem you described.

jwb


--
You received this message because you are subscribed to the Google Groups "Logog" group.
To view this discussion on the web visit https://groups.google.com/d/msg/logog/-/ZiVntAryTfsJ.
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
Gigantic Software
2102 Business Center Drive
Suite 210-D
Irvine, CA   92612-1001
http://www.giganticsoftware.com
T: (949) 892-3526 F: (206) 309-0850
Reply all
Reply to author
Forward
Message has been deleted
0 new messages