Using Google's logging library (glog-0.3.2), are the individual entries sent to the log wrapped by a mutex? That is, can other entries corrupt the entry currently being saved?
I guess that translates to: is glog threadsafe?
And if the logger is set to echo to console as well as to file, short of having my own mutex, is there any way to block printf
/cout
from corrupting the output from LOG()
? I suspect not but wondered if perhaps there is a way to lock the mutex that can wrap several statements.
Unfortunately, the "Raw Logging" info from the glog docs is misleading. raw_logging is a reduced-functionality logging mechanism in GLOG that is useful for situations that are prone to deadlock or other possible re-entrant situations.
If you look at logging.h and logging.c, you'll see that the normal, full-featured logging in glog is also thread-safe. This is achieved as follows:
Yes, glog can be threadsafe.
Raw Logging
The header file can be used for thread-safe logging, which does not allocate any memory or acquire any locks. Therefore, the macros defined in this header file can be used by low-level memory allocation and synchronization code. Please check src/glog/raw_logging.h.in for detail.
http://google-glog.googlecode.com/svn/trunk/doc/glog.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With