ODIN
tjlog_code.h
1 #include <tjutils/tjlog.h>
2 
3 
4 template<class C>
5  void Log<C>::register_comp() {
6 
7  if(!registered) { // retry until LogBase:global is initialized
8  registered=register_component(C::get_compName(),&(Log<C>::set_log_level));
9  if(registered) {
10  const char* env=getenv(C::get_compName());
11  if(env) set_log_level(logPriority(atoi(env)));
12  }
13  }
14  if(!registered) { // global may not be initialized yet
15 
16  // Disable tracing until global becomes available
17  logLevel=noLog;
18  constrLevel=noLog;
19  }
20 
21  }
22 
23 
24 
25 template<class C>
26  Log<C>::Log(const char* objectLabel, const char* functionName, logPriority level)
27  : LogBase(C::get_compName(),objectLabel,0,functionName), constrLevel(level) {
28  register_comp();
29  ODINLOG(*this,constrLevel) << "START" << STD_endl;
30  }
31 
32 
33 template<class C>
34  Log<C>::Log(const Labeled* labeledObject, const char* functionName, logPriority level)
35  : LogBase(C::get_compName(),0,labeledObject,functionName), constrLevel(level) {
36  register_comp();
37  ODINLOG(*this,constrLevel) << "START" << STD_endl;
38  }
39 
40 
41 template<class C>
43  ODINLOG(*this,constrLevel) << "END" << STD_endl;
44  }
45 
46 
47 template<class C>
49  if(level!=ignoreArgument) logLevel=level;
50  return logLevel;
51  }
52 
53 
55 
56 
57 // unregister logging component by local static object if shared library is unloaded
58 template<class C>
59 class LogUnregister {
60  public:
61  LogUnregister() {}
62  ~LogUnregister() {LogBase::unregister_component(C::get_compName());}
63 };
64 
65 
66 #define LOGGROUNDWORK(COMPONENT) \
67 template class Log<COMPONENT>; \
68 EMPTY_TEMPL_LIST logPriority Log<COMPONENT>::logLevel=RELEASE_LOG_LEVEL; \
69 EMPTY_TEMPL_LIST bool Log<COMPONENT>::registered=false; \
70 static LogUnregister<COMPONENT> COMPONENT ## _unregister;
Definition: tjlog.h:117
Definition: tjlog.h:218
~Log()
Definition: tjlog_code.h:42
Log(const char *objectLabel, const char *functionName, logPriority level=verboseDebug)
Definition: tjlog_code.h:26
logPriority
Definition: tjlog.h:48