[log] BOOST_LOG_GLOBAL_LOGGER_* in DLL
I'm trying to use BOOST_LOG_GLOBAL_LOGGER_DEFAULT( my_logger, boost::log::sources::severity_logger_mtboost::log::trivial::severity_level ) In a dll but it doesn't appear to be getting initialized. The first BOOST_LOG_SEV results in a crash due to core being null. How do I initialize a global logger in a DLL?
On Mar 19, 2014, at 8:04 PM, Michael Marcin
I'm trying to use
BOOST_LOG_GLOBAL_LOGGER_DEFAULT( my_logger, boost::log::sources::severity_logger_mtboost::log::trivial::severity_level )
In a dll but it doesn't appear to be getting initialized.
The first BOOST_LOG_SEV results in a crash due to core being null.
How do I initialize a global logger in a DLL?
Is it a "managed" DLL? This may no longer be relevant - but some years ago I was astonished (you might even say outraged) to discover that a "managed" DLL did not guarantee to initialize static "unmanaged" objects. I wondered how this could be called C++, since to me construction and destruction is one of the fundamental promises of the language. Apologies if this is completely irrelevant to your problem.
On 3/20/2014 2:17 AM, Nat Goodspeed wrote:
On Mar 19, 2014, at 8:04 PM, Michael Marcin
wrote: I'm trying to use
BOOST_LOG_GLOBAL_LOGGER_DEFAULT( my_logger, boost::log::sources::severity_logger_mtboost::log::trivial::severity_level )
In a dll but it doesn't appear to be getting initialized.
The first BOOST_LOG_SEV results in a crash due to core being null.
How do I initialize a global logger in a DLL?
Is it a "managed" DLL?
This may no longer be relevant - but some years ago I was astonished (you might even say outraged) to discover that a "managed" DLL did not guarantee to initialize static "unmanaged" objects. I wondered how this could be called C++, since to me construction and destruction is one of the fundamental promises of the language.
Apologies if this is completely irrelevant to your problem.
Unfortunately it is not managed, but thanks for the tip in any event.
On Thu, Mar 20, 2014 at 8:41 PM, Michael Marcin
Unfortunately it is not managed, but thanks for the tip in any event.
"If your application consists of more than one module (e.g. an exe and one or several dll's) that use Boost.Log, the library must be built as a shared object. If you have a single executable or a single module that works with Boost.Log, you may build the library as a static library." Source: http://www.boost.org/doc/libs/1_55_0/libs/log/doc/html/log/installation/conf... Are you sure you did compile Boost.Log itself as a dll too? In my setup I'm "cheating": I have my own specific logging interface exposed by one module (dll) which internally uses a static versdion of Boost.Log, which is equivalent to haveing Boost.Log as a dll in some ways.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 3/20/2014 5:26 PM, Klaim - Joël Lamotte wrote:
On Thu, Mar 20, 2014 at 8:41 PM, Michael Marcin
mailto:mike.marcin@gmail.com> wrote Unfortunately it is not managed, but thanks for the tip in any event.
"If your application consists of more than one module (e.g. an exe and one or several dll's) that use Boost.Log, the library must be built as a shared object. If you have a single executable or a single module that works with Boost.Log, you may build the library as a static library." Source: http://www.boost.org/doc/libs/1_55_0/libs/log/doc/html/log/installation/conf...
Are you sure you did compile Boost.Log itself as a dll too?
In my setup I'm "cheating": I have my own specific logging interface exposed by one module (dll) which internally uses a static versdion of Boost.Log, which is equivalent to haveing Boost.Log as a dll in some ways.
Specifically I have boost Log compiled as a static library but I'm only using boost.log from a single dll so from my reading of that guideline it doesn't apply.
On 3/20/2014 7:27 PM, Michael Marcin wrote:
Specifically I have boost Log compiled as a static library but I'm only using boost.log from a single dll so from my reading of that guideline it doesn't apply.
In the meantime I've just changed to using a function local static and relying upon c++11 magic statics to make it's initialization safe. i.e. logger_type& my_logger() { static logger_type lg; return lg; } BOOST_LOG_SEV( my_logger(), ... )
On Fri, Mar 21, 2014 at 1:27 AM, Michael Marcin
Specifically I have boost Log compiled as a static library but I'm only using boost.log from a single dll so from my reading of that guideline it doesn't apply.
Except of course if the boost.log headers are included and used in api headers of your dll, which would make user code of the dll also need boost.log and as it's static, they would create different instances. However it might not be your problem indeed.
participants (3)
-
Klaim - Joël Lamotte
-
Michael Marcin
-
Nat Goodspeed