loggingevent.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: loggingevent.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
#define LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <memory>
#include <log4cplus/loglevel.h>
#include <log4cplus/ndc.h>
#include <log4cplus/mdc.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/timehelper.h>
#include <log4cplus/thread/threads.h>
namespace log4cplus {
namespace spi {
class LOG4CPLUS_EXPORT InternalLoggingEvent {
public:
// Ctors
InternalLoggingEvent(const log4cplus::tstring& logger,
LogLevel loglevel, const log4cplus::tstring& message,
const char* filename, int line, const char * function = nullptr);
InternalLoggingEvent(const log4cplus::tstring& logger,
LogLevel loglevel, const log4cplus::tstring& ndc,
MappedDiagnosticContextMap const & mdc,
const log4cplus::tstring& message,
const log4cplus::tstring& thread,
log4cplus::helpers::Time time, const log4cplus::tstring& file,
int line, const log4cplus::tstring & function
= log4cplus::tstring ()) LOG4CPLUS_ATTRIBUTE_DEPRECATED;
InternalLoggingEvent(const log4cplus::tstring& logger,
LogLevel loglevel, const log4cplus::tstring& ndc,
MappedDiagnosticContextMap const & mdc,
const log4cplus::tstring& message,
const log4cplus::tstring& thread,
const log4cplus::tstring& thread2,
log4cplus::helpers::Time time, const log4cplus::tstring& file,
int line, const log4cplus::tstring & function
= log4cplus::tstring ());
InternalLoggingEvent ();
InternalLoggingEvent(
const log4cplus::spi::InternalLoggingEvent& rhs);
virtual ~InternalLoggingEvent();
void setLoggingEvent (const log4cplus::tstring & logger,
LogLevel ll, const log4cplus::tstring & message,
const char * filename, int line,
const char * function = nullptr);
void setFunction (char const * func);
void setFunction (log4cplus::tstring const &);
// public virtual methods
virtual const log4cplus::tstring& getMessage() const;
virtual unsigned int getType() const;
virtual std::unique_ptr<InternalLoggingEvent> clone() const;
// public methods
const log4cplus::tstring& getLoggerName() const
{
return loggerName;
}
LogLevel getLogLevel() const
{
return ll;
}
const log4cplus::tstring& getNDC() const
{
if (!ndcCached)
{
ndc = log4cplus::getNDC().get();
ndcCached = true;
}
return ndc;
}
MappedDiagnosticContextMap const & getMDCCopy () const
{
if (!mdcCached)
{
mdc = log4cplus::getMDC().getContext ();
mdcCached = true;
}
return mdc;
}
tstring const & getMDC (tstring const & key) const;
const log4cplus::tstring& getThread() const
{
if (! threadCached)
{
thread = thread::getCurrentThreadName ();
threadCached = true;
}
return thread;
}
const log4cplus::tstring& getThread2() const
{
if (! thread2Cached)
{
thread2 = thread::getCurrentThreadName2 ();
thread2Cached = true;
}
return thread2;
}
const log4cplus::helpers::Time& getTimestamp() const
{
return timestamp;
}
const log4cplus::tstring& getFile() const
{
return file;
}
int getLine() const { return line; }
log4cplus::tstring const & getFunction () const
{
return function;
}
void gatherThreadSpecificData () const;
void swap (InternalLoggingEvent &);
// public operators
log4cplus::spi::InternalLoggingEvent&
operator=(const log4cplus::spi::InternalLoggingEvent& rhs);
// static methods
static unsigned int getDefaultType();
protected:
// Data
log4cplus::tstring message;
log4cplus::tstring loggerName;
LogLevel ll;
mutable log4cplus::tstring ndc;
mutable MappedDiagnosticContextMap mdc;
mutable log4cplus::tstring thread;
mutable log4cplus::tstring thread2;
log4cplus::helpers::Time timestamp;
log4cplus::tstring file;
log4cplus::tstring function;
int line;
mutable bool threadCached;
mutable bool thread2Cached;
mutable bool ndcCached;
mutable bool mdcCached;
};
} // end namespace spi
} // end namespace log4cplus
#endif // LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
log4cplus::MDC::getContext
MappedDiagnosticContextMap const & getContext() const
log4cplus::NDC::get
log4cplus::tstring const & get() const
Used when printing the diagnostic context.
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
log4cplus::spi::InternalLoggingEvent::clone
virtual std::unique_ptr< InternalLoggingEvent > clone() const
Returns a copy of this object.
log4cplus::spi::InternalLoggingEvent::getThread
const log4cplus::tstring & getThread() const
The name of thread in which this logging event was generated.
Definition loggingevent.h:160
log4cplus::spi::InternalLoggingEvent::function
log4cplus::tstring function
Definition loggingevent.h:225
log4cplus::spi::InternalLoggingEvent::message
log4cplus::tstring message
Definition loggingevent.h:216
log4cplus::spi::InternalLoggingEvent::operator=
log4cplus::spi::InternalLoggingEvent & operator=(const log4cplus::spi::InternalLoggingEvent &rhs)
log4cplus::spi::InternalLoggingEvent::thread2
log4cplus::tstring thread2
Definition loggingevent.h:222
log4cplus::spi::InternalLoggingEvent::mdcCached
bool mdcCached
Indicates whether or not the MDC has been retrieved.
Definition loggingevent.h:233
log4cplus::spi::InternalLoggingEvent::threadCached
bool threadCached
Indicates whether or not the Threadname has been retrieved.
Definition loggingevent.h:228
log4cplus::spi::InternalLoggingEvent::ll
LogLevel ll
Definition loggingevent.h:218
log4cplus::spi::InternalLoggingEvent::thread2Cached
bool thread2Cached
Definition loggingevent.h:229
log4cplus::spi::InternalLoggingEvent::getMDCCopy
MappedDiagnosticContextMap const & getMDCCopy() const
Definition loggingevent.h:147
log4cplus::spi::InternalLoggingEvent::mdc
MappedDiagnosticContextMap mdc
Definition loggingevent.h:220
log4cplus::spi::InternalLoggingEvent::file
log4cplus::tstring file
Definition loggingevent.h:224
log4cplus::spi::InternalLoggingEvent::setLoggingEvent
void setLoggingEvent(const log4cplus::tstring &logger, LogLevel ll, const log4cplus::tstring &message, const char *filename, int line, const char *function=nullptr)
log4cplus::spi::InternalLoggingEvent::gatherThreadSpecificData
void gatherThreadSpecificData() const
log4cplus::spi::InternalLoggingEvent::InternalLoggingEvent
InternalLoggingEvent(const log4cplus::tstring &logger, LogLevel loglevel, const log4cplus::tstring &ndc, MappedDiagnosticContextMap const &mdc, const log4cplus::tstring &message, const log4cplus::tstring &thread, log4cplus::helpers::Time time, const log4cplus::tstring &file, int line, const log4cplus::tstring &function=log4cplus::tstring()) LOG4CPLUS_ATTRIBUTE_DEPRECATED
log4cplus::spi::InternalLoggingEvent::timestamp
log4cplus::helpers::Time timestamp
Definition loggingevent.h:223
log4cplus::spi::InternalLoggingEvent::line
int line
Definition loggingevent.h:226
log4cplus::spi::InternalLoggingEvent::getThread2
const log4cplus::tstring & getThread2() const
Definition loggingevent.h:172
log4cplus::spi::InternalLoggingEvent::swap
void swap(InternalLoggingEvent &)
log4cplus::spi::InternalLoggingEvent::getLine
int getLine() const
The is the line where this log statement was written.
Definition loggingevent.h:196
log4cplus::spi::InternalLoggingEvent::getTimestamp
const log4cplus::helpers::Time & getTimestamp() const
Time stamp when the event was created.
Definition loggingevent.h:184
log4cplus::spi::InternalLoggingEvent::ndc
log4cplus::tstring ndc
Definition loggingevent.h:219
log4cplus::spi::InternalLoggingEvent::getLoggerName
const log4cplus::tstring & getLoggerName() const
The logger of the logging event.
Definition loggingevent.h:125
log4cplus::spi::InternalLoggingEvent::getType
virtual unsigned int getType() const
Returns the 'type' of InternalLoggingEvent.
log4cplus::spi::InternalLoggingEvent::getMessage
virtual const log4cplus::tstring & getMessage() const
The application supplied message of logging event.
log4cplus::spi::InternalLoggingEvent::getMDC
tstring const & getMDC(tstring const &key) const
log4cplus::spi::InternalLoggingEvent::setFunction
void setFunction(char const *func)
log4cplus::spi::InternalLoggingEvent::getNDC
const log4cplus::tstring & getNDC() const
The nested diagnostic context (NDC) of logging event.
Definition loggingevent.h:137
log4cplus::spi::InternalLoggingEvent::loggerName
log4cplus::tstring loggerName
Definition loggingevent.h:217
log4cplus::spi::InternalLoggingEvent::InternalLoggingEvent
InternalLoggingEvent(const log4cplus::tstring &logger, LogLevel loglevel, const log4cplus::tstring &message, const char *filename, int line, const char *function=nullptr)
Instantiate a LoggingEvent from the supplied parameters.
log4cplus::spi::InternalLoggingEvent::getLogLevel
LogLevel getLogLevel() const
LogLevel of logging event.
Definition loggingevent.h:131
log4cplus::spi::InternalLoggingEvent::thread
log4cplus::tstring thread
Definition loggingevent.h:221
log4cplus::spi::InternalLoggingEvent::ndcCached
bool ndcCached
Indicates whether or not the NDC has been retrieved.
Definition loggingevent.h:231
log4cplus::spi::InternalLoggingEvent::getFile
const log4cplus::tstring & getFile() const
The is the file where this log statement was written.
Definition loggingevent.h:190
log4cplus::spi::InternalLoggingEvent::getFunction
log4cplus::tstring const & getFunction() const
Definition loggingevent.h:198
log4cplus::spi::InternalLoggingEvent::getDefaultType
static unsigned int getDefaultType()
config.hxx
LOG4CPLUS_ATTRIBUTE_DEPRECATED
#define LOG4CPLUS_ATTRIBUTE_DEPRECATED
Definition config.hxx:136
loglevel.h
This header defines the LogLevel type.
mdc.h
log4cplus::helpers
Definition appender.h:50
log4cplus::helpers::Time
chrono::time_point< Clock, Duration > Time
Definition timehelper.h:54
log4cplus::spi
Definition layout.h:62
log4cplus::thread::getCurrentThreadName
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName()
log4cplus::thread::getCurrentThreadName2
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2()
log4cplus
Definition appender.h:46
log4cplus::getNDC
LOG4CPLUS_EXPORT NDC & getNDC()
Return a reference to the singleton object.
log4cplus::getMDC
LOG4CPLUS_EXPORT MDC & getMDC()
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::MappedDiagnosticContextMap
std::map< tstring, tstring > MappedDiagnosticContextMap
Definition mdc.h:43
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition loglevel.h:48
ndc.h
This header defined the NDC class.
threads.h
timehelper.h
tstring.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141