2 * Copyright (c) 2002, Robert Collins..
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #ifndef SETUP_LOGSINGLETON_H
17 #define SETUP_LOGSINGLETON_H
27 // Logging class. Default logging level is PLAIN.
28 class LogSingleton
: public std::ostream
32 static LogSingleton
&GetInstance();
33 static void SetInstance(LogSingleton
&anInstance
);
35 /* Some platforms don't call destructors. So this call exists
36 * which guarantees to flush any log data...
37 * but doesn't call generic C++ destructors
39 __attribute__ ((noreturn
)) virtual void exit (int, bool = true) = 0;
40 virtual ~LogSingleton();
41 // get a specific verbosity stream.
42 virtual std::ostream
&operator() (enum log_level level
) = 0;
44 friend std::ostream
& endLog(std::ostream
& outs
);
47 LogSingleton(std::streambuf
* aStream
); // Only child classs can be created.
48 LogSingleton (LogSingleton
const &); // no copy constructor
49 LogSingleton
&operator = (LogSingleton
const&); // no assignment operator
50 virtual void endEntry() = 0; // the current in-progress entry is complete.
52 static LogSingleton
*theInstance
;
55 /* End of a Log comment */
56 extern std::ostream
& endLog(std::ostream
& outs
);
58 #define Log(X) (LogSingleton::GetInstance ()(X))
60 // Log adapators for printf-style output
61 void LogBabblePrintf(const char *fmt
, ...);
62 void LogPlainPrintf(const char *fmt
, ...);
64 #endif /* SETUP_LOGSINGLETON_H */