log4cplus  2.0.0
tracelogger.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    tracelogger.h
00004 // Created: 1/2009
00005 // Author:  Vaclav Haisman
00006 //
00007 //
00008 // Copyright 2009-2015 Tad E. Smith
00009 //
00010 // Licensed under the Apache License, Version 2.0 (the "License");
00011 // you may not use this file except in compliance with the License.
00012 // You may obtain a copy of the License at
00013 //
00014 //     http://www.apache.org/licenses/LICENSE-2.0
00015 //
00016 // Unless required by applicable law or agreed to in writing, software
00017 // distributed under the License is distributed on an "AS IS" BASIS,
00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 // See the License for the specific language governing permissions and
00020 // limitations under the License.
00021 
00024 #ifndef LOG4CPLUS_TRACELOGGER_H
00025 #define LOG4CPLUS_TRACELOGGER_H
00026 
00027 #include <log4cplus/config.hxx>
00028 
00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00030 #pragma once
00031 #endif
00032 
00033 #include <log4cplus/logger.h>
00034 
00035 
00036 namespace log4cplus
00037 {
00038 
00039 
00050 class TraceLogger
00051 {
00052 public:
00053     TraceLogger(Logger l, log4cplus::tstring _msg,
00054         const char* _file = LOG4CPLUS_CALLER_FILE (),
00055         int _line = LOG4CPLUS_CALLER_LINE (),
00056         char const * _function = LOG4CPLUS_CALLER_FUNCTION ())
00057         : logger(std::move (l)), msg(std::move (_msg)), file(_file),
00058           function(_function), line(_line)
00059     {
00060         if(logger.isEnabledFor(TRACE_LOG_LEVEL))
00061             logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("ENTER: ") + msg,
00062                 file, line, function);
00063     }
00064 
00065     ~TraceLogger()
00066     {
00067         if(logger.isEnabledFor(TRACE_LOG_LEVEL))
00068             logger.forcedLog(TRACE_LOG_LEVEL, LOG4CPLUS_TEXT("EXIT:  ") + msg,
00069                 file, line, function);
00070     }
00071 
00072 private:
00073     TraceLogger (TraceLogger const &);
00074     TraceLogger & operator = (TraceLogger const &);
00075 
00076     Logger logger;
00077     log4cplus::tstring msg;
00078     const char* file;
00079     const char* function;
00080     int line;
00081 };
00082 
00083 
00084 } // log4cplus
00085 
00086 
00087 #endif // LOG4CPLUS_TRACELOGGER_H