/src/log4cplus/include/log4cplus/tracelogger.h
Line | Count | Source |
1 | | // -*- C++ -*- |
2 | | // Module: Log4CPLUS |
3 | | // File: tracelogger.h |
4 | | // Created: 1/2009 |
5 | | // Author: Vaclav Haisman |
6 | | // |
7 | | // |
8 | | // Copyright 2009-2017 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 LOG4CPLUS_TRACELOGGER_H |
25 | | #define LOG4CPLUS_TRACELOGGER_H |
26 | | |
27 | | #include <log4cplus/config.hxx> |
28 | | |
29 | | #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) |
30 | | #pragma once |
31 | | #endif |
32 | | |
33 | | #include <log4cplus/logger.h> |
34 | | |
35 | | |
36 | | namespace log4cplus |
37 | | { |
38 | | |
39 | | |
40 | | /** |
41 | | * This class is used to produce "Trace" logging. When an instance of |
42 | | * this class is created, it will log a <code>"ENTER: " + msg</code> |
43 | | * log message if TRACE_LOG_LEVEL is enabled for <code>logger</code>. |
44 | | * When an instance of this class is destroyed, it will log a |
45 | | * <code>"ENTER: " + msg</code> log message if TRACE_LOG_LEVEL is enabled |
46 | | * for <code>logger</code>. |
47 | | * <p> |
48 | | * @see LOG4CPLUS_TRACE |
49 | | */ |
50 | | class TraceLogger |
51 | | { |
52 | | public: |
53 | | TraceLogger(Logger l, log4cplus::tstring _msg, |
54 | | const char* _file = LOG4CPLUS_CALLER_FILE (), |
55 | | int _line = LOG4CPLUS_CALLER_LINE (), |
56 | | char const * _function = LOG4CPLUS_CALLER_FUNCTION ()) |
57 | | : logger(std::move (l)), msg(std::move (_msg)), file(_file), |
58 | | function(_function), line(_line) |
59 | 0 | { |
60 | 0 | if(logger.isEnabledFor(TRACE_LOG_LEVEL)) |
61 | 0 | logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("ENTER: ") + msg, |
62 | 0 | file, line, function); |
63 | 0 | } |
64 | | |
65 | | ~TraceLogger() |
66 | 0 | { |
67 | 0 | if(logger.isEnabledFor(TRACE_LOG_LEVEL)) |
68 | 0 | logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("EXIT: ") + msg, |
69 | 0 | file, line, function); |
70 | 0 | } |
71 | | |
72 | | private: |
73 | | TraceLogger (TraceLogger const &); |
74 | | TraceLogger & operator = (TraceLogger const &); |
75 | | |
76 | | Logger logger; |
77 | | log4cplus::tstring msg; |
78 | | const char* file; |
79 | | const char* function; |
80 | | int line; |
81 | | }; |
82 | | |
83 | | |
84 | | } // log4cplus |
85 | | |
86 | | |
87 | | #endif // LOG4CPLUS_TRACELOGGER_H |