wxthon / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Logging from a library #113

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use glog in two libraries
2. Use two libraries that use glog in one project.
3. Call initialize code for both libraries.

What is the expected output? What do you see instead?

I expect that glog initializes quietly. Instead it shows me a message "You 
called InitGoogleLogging() twice".

What version of the product are you using? On what operating system?

glog 0.3.2 on windows

Please provide any additional information below.

What do you propose to handle such a situation when a project consists of a 
multiple libraries which are using glog? How to check if glog is already 
initialized? Can glog be initiazed at compile time?

Original issue reported on code.google.com by Van...@gmail.com on 23 Jan 2012 at 10:36

GoogleCodeExporter commented 9 years ago
InitGoogleLogging should really be part of the application. Libraries are free 
to use the LOG macros but they can't make assumptions about how the user wants 
to initialize logging. I believe InitGoogleLogging is meant to be called in the 
application 'main' (or similar)

Original comment by diwakerg...@gmail.com on 15 Mar 2012 at 9:04

GoogleCodeExporter commented 9 years ago
Hm... what about dynamic loading?
I want to use logging in an NPAPI plugin (it is loaded dynamically by a 
browser).
The problem is that I can't make an assumption that browser will call 
InitGoogleLogging (I think it doesn't. I even can't be sure what it links to 
glog). And if I develop another plugin, I want to be sure that I called init 
only once.
Can I live without initialization?

Hm... What I can do is to link a plugin with glog statically and initialize 
glog when a browser calls NP_Initialize. But then each plugin will have its own 
glog copy. And if a browser rendering engine also links to glog, I might have a 
problem.

> I believe InitGoogleLogging is meant to be called in the application 'main' 
(or similar)

So a library must export this symbol? Or an application should link to glog?

Original comment by Van...@gmail.com on 15 Mar 2012 at 9:28

GoogleCodeExporter commented 9 years ago
Even if I link glog statically, I'll still have one InitGoogleLogging symbol :(
So, won't glog crash if I call init multiple times?

Original comment by Van...@gmail.com on 9 Jul 2012 at 11:57

GoogleCodeExporter commented 9 years ago
Could glog expose a function "IsGoogleLoggingInitialized()"?

Original comment by Van...@gmail.com on 9 Jul 2012 at 3:02