12 #include <arc/Thread.h> 13 #include <arc/IString.h> 62 std::ostream&
operator<<(std::ostream& os,
const LoggerFormat& format);
133 const std::string& identifier);
158 static std::string getDefaultIdentifier();
165 void setDomain(std::string domain);
177 std::string identifier;
186 friend std::ostream&
operator<<(std::ostream& os,
328 std::ostream& destination;
355 LogFile(
const std::string& path);
407 void operator=(
const LogFile& unique);
410 std::ofstream destination;
414 std::list<std::string*> cache;
416 Glib::Mutex file_mutex;
419 class LoggerContextRef;
423 class LoggerContext {
425 friend class LoggerContextRef;
434 std::list<LogDestination*> destinations;
439 LoggerContext(
LogLevel thr):usage_count(0),threshold(thr) { };
441 LoggerContext(
const LoggerContext& ctx):
442 usage_count(0),destinations(ctx.destinations),threshold(ctx.threshold) { };
444 ~LoggerContext(
void);
509 const std::string& subdomain);
517 const std::string& subdomain,
576 const std::list<std::string>& subdomains);
587 const std::string& domain);
631 template<
class T0,
class T1>
633 const T0& t0,
const T1& t1) {
634 msg(LogMessage(level, IString(str, t0, t1)));
637 template<
class T0,
class T1,
class T2>
639 const T0& t0,
const T1& t1,
const T2& t2) {
640 msg(LogMessage(level, IString(str, t0, t1, t2)));
643 template<
class T0,
class T1,
class T2,
class T3>
645 const T0& t0,
const T1& t1,
const T2& t2,
const T3& t3) {
646 msg(LogMessage(level, IString(str, t0, t1, t2, t3)));
649 template<
class T0,
class T1,
class T2,
class T3,
class T4>
651 const T0& t0,
const T1& t1,
const T2& t2,
const T3& t3,
653 msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4)));
656 template<
class T0,
class T1,
class T2,
class T3,
class T4,
659 const T0& t0,
const T1& t1,
const T2& t2,
const T3& t3,
660 const T4& t4,
const T5& t5) {
661 msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4, t5)));
664 template<
class T0,
class T1,
class T2,
class T3,
class T4,
667 const T0& t0,
const T1& t1,
const T2& t2,
const T3& t3,
668 const T4& t4,
const T5& t5,
const T6& t6) {
669 msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4, t5, t6)));
672 template<
class T0,
class T1,
class T2,
class T3,
class T4,
673 class T5,
class T6,
class T7>
675 const T0& t0,
const T1& t1,
const T2& t2,
const T3& t3,
676 const T4& t4,
const T5& t5,
const T6& t6,
const T7& t7) {
677 msg(LogMessage(level, IString(str, t0, t1, t2, t3, t4, t5, t6, t7)));
694 Logger(
const Logger& unique);
700 void operator=(
const Logger& unique);
707 std::string getDomain();
716 void log(
const LogMessage& message);
725 std::string context_id;
727 LoggerContext context;
729 LoggerContext& getContext(
void);
735 #define rootLoggerMagic (0xF6569201) 736 static Logger *rootLogger;
737 static std::map<std::string,LogLevel>* defaultThresholds;
738 static unsigned int rootLoggerMark;
745 #define rootLogger getRootLogger() 747 #define LOG(LGR, THR, FSTR, ...) { if ((LGR).getThreshold() >= (THR)(LGR).msg((THR), (FSTR), ...); } 749 #endif // __ARC_LOGGER__ Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
void setMaxSize(int newsize)
Set maximal allowed size of file.
Glib::Mutex mutex
A mutex for synchronization.
Definition: Logger.h:266
Logger(Logger &parent, const std::string &subdomain)
Creates a logger.
A base class for log destinations.
Definition: Logger.h:207
static void ReopenAll()
Reopen all LogFile objects.
bool operator!(void)
Returns true if this instance is invalid.
void setDestinations(const std::list< LogDestination *> &destinations)
Set LogDestinations.
static LogFormat getDefaultFormat()
Returns currently assigned default format.
LogMessage(LogLevel level, const IString &message)
Creates a LogMessage with the specified level and message text.
static void setDefaultFormat(const LogFormat &newformat)
Set format for any new log destination.
LogFormat getFormat() const
Returns currently assigned format.
~Logger()
Destroys a logger.
void addDestination(LogDestination &destination)
Adds a LogDestination.
A class for logging to files.
Definition: Logger.h:344
Only message level is printed.
Definition: Logger.h:44
void setPrefix(const std::string &prefix)
Set a prefix for this log destination to be logged before messages.
Only message is printed.
Definition: Logger.h:50
void setIdentifier(std::string identifier)
Sets the identifier of the LogMessage.
LogStream(std::ostream &destination)
Creates a LogStream connected to an ostream.
void msg(LogLevel level, const std::string &str)
Logs a message text.
Definition: Logger.h:621
void setReopen(bool newreopen)
Set file reopen on every write.
A class for logging to ostreams.
Definition: Logger.h:290
A logger class.
Definition: Logger.h:493
LogDestination()
Default constructor. Protected since subclasses should be used instead.
LogFormat format
Format to use in this LogDestination.
Definition: Logger.h:269
Class used for localised output of log messages.
Definition: IString.h:180
void setThreadContext(void)
Creates per-thread context.
void setFormat(const LogFormat &newformat)
Set format for this log destination.
~LogFile()
Ordinary destructor.
void deleteDestinations(LogDestination *exclude=NULL)
Remove all LogDestinations and delete LogDestination objects.
LogLevel
Logging levels for tagging and filtering log messages.
Definition: Logger.h:20
void setBackups(int newbackup)
Set number of backups to store.
A class for log messages.
Definition: Logger.h:107
friend std::ostream & operator<<(std::ostream &os, const LogDestination &dest)
Sets iword and pword for format and prefix.
std::string prefix
Prefix to use in this log destination.
Definition: Logger.h:275
void addDestinations(const std::list< LogDestination *> &destinations)
Adds LogDestinations.
virtual void log(const LogMessage &message)
Writes a LogMessage to the stream.
LogLevel old_level_to_level(unsigned int old_level)
Convert an old-style log level (int from 0 to 5) to a LogLevel.
static Logger & getRootLogger()
The root Logger.
std::ostream & operator<<(std::ostream &, const Period &)
Prints a Period-object to the given ostream – typically cout.
LogLevel string_to_level(const std::string &str)
Convert string to a LogLevel.
void msg(LogMessage message)
Sends a LogMessage.
LogLevel istring_to_level(const std::string &llStr)
Convert string case-insensitively to a LogLevel.
LogFormat
Output formats. Defines prefix for each message.
Definition: Logger.h:35
std::string level_to_string(const LogLevel &level)
Convert LogLevel to a string.
LogLevel getLevel() const
Returns the level of the LogMessage.
virtual void log(const LogMessage &message)
Writes a LogMessage to the file.
All information except domain is printed.
Definition: Logger.h:42
const std::list< LogDestination * > & getDestinations(void) const
Obtains current LogDestinations.
virtual void log(const LogMessage &message)=0
Logs a LogMessage to this LogDestination.
WARNING level designates potentially harmful situations.
Definition: Logger.h:27
std::string getPrefix() const
Returns currently assignd prefix.
LogLevel getThreshold() const
Returns the threshold of this logger.
void removeDestinations(void)
Removes all LogDestinations.
friend std::ostream & operator<<(std::ostream &os, const LogMessage &message)
Printing of LogMessages to ostreams.
All information about message is printed.
Definition: Logger.h:37
void setThreshold(LogLevel threshold)
Sets the logging threshold.
static void setThresholdForDomain(LogLevel threshold, const std::list< std::string > &subdomains)
Sets the threshold for domain.
void Reopen()
Reopen file if currently open.