1 // -*- C++ -*-
2 // Module:  Log4CPLUS
3 // File:    loglog.h
4 // Created: 6/2001
5 // Author:  Tad E. Smith
6 //
7 //
8 // Copyright 2001-2010 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 //     http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
22 /** @file */
23 
24 #ifndef DCMTK_LOG4CPLUS_HELPERS_LOGLOG
25 #define DCMTK_LOG4CPLUS_HELPERS_LOGLOG
26 
27 #include "dcmtk/oflog/config.h"
28 
29 #if defined (DCMTK_LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include "dcmtk/oflog/tstring.h"
34 #include "dcmtk/oflog/streams.h"
35 #include "dcmtk/oflog/thread/syncprim.h"
36 
37 
38 namespace dcmtk {
39 namespace log4cplus {
40     namespace helpers {
41 
42         /**
43          * This class used to output log statements from within the log4cplus package.
44          *
45          * Log4cplus components cannot make log4cplus logging calls. However, it is
46          * sometimes useful for the user to learn about what log4cplus is
47          * doing. You can enable log4cplus internal logging by defining the
48          * <b>log4cplus.configDebug</b> variable.
49          *
50          * All log4cplus internal debug calls go to <code>cout</code>
51          * where as internal error messages are sent to
52          * <code>cerr</code>. All internal messages are prepended with
53          * the string "log4clus: ".
54          */
55         class DCMTK_LOG4CPLUS_EXPORT LogLog
56         {
57         public:
58             //! Return type of getLogLog().
59             typedef LogLog * Ptr;
60 
61             /**
62              * Returns a reference to the <code>LogLog</code> singleton.
63              */
64             static Ptr getLogLog();
65 
66 
67             /**
68              * Allows to enable/disable log4cplus internal logging.
69              */
70             void setInternalDebugging(bool enabled);
71 
72             /**
73              * In quite mode no LogLog generates strictly no output, not even
74              * for errors.
75              *
76              * @param quietMode A true for not
77              */
78             void setQuietMode(bool quietMode);
79 
80             /**
81              * This method is used to output log4cplus internal debug
82              * statements. Output goes to <code>STD_NAMESPACE cout</code>.
83              */
84             void debug(const log4cplus::tstring& msg) const;
85             void debug(tchar const * msg) const;
86 
87             /**
88              * This method is used to output log4cplus internal error
89              * statements. There is no way to disable error
90              * statements.  Output goes to
91              * <code>STD_NAMESPACE cerr</code>. Optionally, this method can
92              * throw STD_NAMESPACE runtime_error exception too.
93              */
94             void error(const log4cplus::tstring& msg, bool throw_flag = false) const;
95             void error(tchar const * msg, bool throw_flag = false) const;
96 
97             /**
98              * This method is used to output log4cplus internal warning
99              * statements. There is no way to disable warning statements.
100              * Output goes to <code>STD_NAMESPACE cerr</code>.
101              */
102             void warn(const log4cplus::tstring& msg) const;
103             void warn(tchar const * msg) const;
104 
105             // Public ctor and dtor to be used only by internal::DefaultContext.
106             LogLog();
107             virtual ~LogLog();
108 
109         private:
110             enum TriState
111             {
112                 TriUndef = -1,
113                 TriFalse,
114                 TriTrue
115             };
116 
117             DCMTK_LOG4CPLUS_PRIVATE
118             void logging_worker (tostream & os,
119                 bool (LogLog:: * cond) () const, tchar const *,
120                 tchar const *, bool throw_flag = false) const;
121 
122             DCMTK_LOG4CPLUS_PRIVATE static void set_tristate_from_env (TriState *,
123                 tchar const * envvar);
124 
125             DCMTK_LOG4CPLUS_PRIVATE bool get_quiet_mode () const;
126             DCMTK_LOG4CPLUS_PRIVATE bool get_not_quiet_mode () const;
127             DCMTK_LOG4CPLUS_PRIVATE bool get_debug_mode () const;
128 
129             // Data
130             mutable TriState debugEnabled;
131             mutable TriState quietMode;
132             thread::Mutex mutex;
133 
134             DCMTK_LOG4CPLUS_PRIVATE LogLog(const LogLog&);
135             DCMTK_LOG4CPLUS_PRIVATE LogLog & operator = (LogLog const &);
136         };
137 
138         DCMTK_LOG4CPLUS_EXPORT LogLog & getLogLog ();
139 
140     } // end namespace helpers
141 } // end namespace log4cplus
142 } // end namespace dcmtk
143 
144 
145 #endif // DCMTK_LOG4CPLUS_HELPERS_LOGLOG
146 
147