/work/dcmtk-install/include/dcmtk/oflog/tracelog.h
Line | Count | Source |
1 | | // -*- C++ -*- |
2 | | // Module: Log4CPLUS |
3 | | // File: tracelog.h |
4 | | // Created: 1/2009 |
5 | | // Author: Vaclav Haisman |
6 | | // |
7 | | // |
8 | | // Copyright 2009-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_TRACELOGGER_H |
25 | | #define DCMTK_LOG4CPLUS_TRACELOGGER_H |
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/logger.h" |
34 | | |
35 | | |
36 | | namespace dcmtk |
37 | | { |
38 | | namespace log4cplus |
39 | | { |
40 | | |
41 | | |
42 | | /** |
43 | | * This class is used to produce "Trace" logging. When an instance of |
44 | | * this class is created, it will log a <code>"ENTER: " + msg</code> |
45 | | * log message if TRACE_LOG_LEVEL is enabled for <code>logger</code>. |
46 | | * When an instance of this class is destroyed, it will log a |
47 | | * <code>"ENTER: " + msg</code> log message if TRACE_LOG_LEVEL is enabled |
48 | | * for <code>logger</code>. |
49 | | * <p> |
50 | | * @see DCMTK_LOG4CPLUS_TRACE |
51 | | */ |
52 | | class TraceLogger |
53 | | { |
54 | | public: |
55 | | TraceLogger(const Logger& l, const log4cplus::tstring& _msg, |
56 | | const char* _file=NULL, int _line=-1) |
57 | | : logger(l), msg(_msg), file(_file), line(_line) |
58 | 0 | { if(logger.isEnabledFor(TRACE_LOG_LEVEL)) |
59 | 0 | logger.forcedLog(TRACE_LOG_LEVEL, DCMTK_LOG4CPLUS_TEXT("ENTER: ") + msg, file, line); |
60 | 0 | } |
61 | | |
62 | | ~TraceLogger() |
63 | 0 | { if(logger.isEnabledFor(TRACE_LOG_LEVEL)) |
64 | 0 | logger.forcedLog(TRACE_LOG_LEVEL, DCMTK_LOG4CPLUS_TEXT("EXIT: ") + msg, file, line); |
65 | 0 | } |
66 | | |
67 | | private: |
68 | | TraceLogger (TraceLogger const &); |
69 | | TraceLogger & operator = (TraceLogger const &); |
70 | | |
71 | | Logger logger; |
72 | | log4cplus::tstring msg; |
73 | | const char* file; |
74 | | int line; |
75 | | }; |
76 | | |
77 | | |
78 | | } // log4cplus |
79 | | } // end namespace dcmtk |
80 | | |
81 | | |
82 | | #endif // DCMTK_LOG4CPLUS_TRACELOGGER_H |