Opened 8 years ago
Closed 8 years ago
#10061 closed Bugs (invalid)
boost::log (boost logging): BOOST_LOG_FUNCTION works only in main thread
Reported by: | anonymous | Owned by: | Andrey Semashev |
---|---|---|---|
Milestone: | To Be Determined | Component: | log |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Consider the following function:
void thread() { BOOST_LOG_FUNCTION(); while(true) { // Create log entry } }
If I just call "thread()" within main() as a function my log entries created in "thread()" look as expected:
[void __cdecl thread(void) (c:\...\maintest.cpp:16)]
However if you use "thread()" within main() as a real thread:
boost::thread t(thread);
the appropriate log-entry containing the scope is empty:
[]
Code snippet:
keywords::format = expr::stream << "[" << expr::format_named_scope("Scope", keywords::format = "%n (%f:%l)")<< "] "
I do not understand this, since the appropriate values FUNCTION and FUNCSIG are always available when manually printed. Operating system: Windows 7. I posted the issue without a solution on stackoverflow a few months ago so that I assume it is a bug:
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
add_global_attribure solved the problem. I am sorry for bothering you. The logging library is really a beautiful piece of software. However, the documentation should be improved. It is very hard to obtain desired information. Keep up the great work!
comment:3 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I recommend reading the Design section in the docs, it explains different types of attributes and gives a good insight on the library architecture. With that kind of knowledge it's easier to explore the library further.
In order the scope names to be present in the output, the named_scope attribute has to be present for the thread that emits the log record. That is, either named_scope has to be added as a global attribute (i.e. with add_global_attribure) or added as a thread-specific attribute in every thread (e.g. by calling add_thread_attribute somewhere early in the thread routine). Please verify that your code does this.
If your code adds the attribute properly then could you please provide a small compilable example so that I'm able to reproduce the problem.