AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
logger.hh
Go to the documentation of this file.
1#ifndef _DRAMA2_LOGGER_INC
2#define _DRAMA2_LOGGER_INC
17/*
18 * History:
19 01-Jul-2014 - TJF - Original version
20 11-May-2015 - TJF - Start of history after development.
21 Revert to using Task * instead of shared_ptr<Task>
22 since using the later would not delay the
23 construction of the logger until after the
24 Task constructor has returned, which has its own
25 problems
26 30-Sep-2016 - TJF - DramaCtxMapType now has a pair of item each thread,
27 a string and the drama context, rather then just
28 the drama context. The string is supplied when
29 threads are registered and is output in a new
30 field in the log file.
31
32 * The above ID is for Doxygen, this one has the format ACMM is looking for.
33 * "@(#) $Id$"
34 */
35
36
37// Define to enable the LogStream class - which does not work
38// on some systems. Currently disabled all the time until we understand
39// what is wrong in more detail.
40
41//#define D2_PROVIDE_LOG_STREAM
42
43#include "DitsTypes.h"
44#include "Ers.h"
45#include <iostream>
46#include <fstream>
47#if defined(__GNUC__) && !defined(__clang__)
48#define _DRAMA_HaveGnuFileBufExt
49#define _DRAMA_GnuFileBufExtOnly(_A_) _A_
50#include <ext/stdio_filebuf.h> // __gnu_cxx::stdio_filebuf
51#else
52#define _DRAMA_GnuFileBufExtOnly(_A_) _A_
53#endif
54
55#include <map>
56#include <thread>
57
58/*
59 * Usable log levels.
60 *
61 * When a log call is made, if the "and" of the supplied log level
62 * and the currently enabled log level is non-zero, then the message
63 * is logged.
64 */
65#define D2LOG_ALL 0xFFFFFFFF
66#define D2LOG_STARTUP 0x01
67#define D2LOG_ERRORS 0x02
68#define D2LOG_ACTENT 0x04
69#define D2LOG_ACTEXIT 0x08
70#define D2LOG_INST 0x10
71#define D2LOG_MSG 0x20
72#define D2LOG_DEBUG 0x40
73#define D2LOG_COMMS 0x80
74#define D2LOG_USER1 0x100
75#define D2LOG_USER2 0x200
76#define D2LOG_USER3 0x400
77#define D2LOG_USER4 0x800
78#define D2LOG_ARGS 0x1000
80#define D2LOG_DRAMA2 0x2000
82#define D2LOG_ALWAYS 0x40000
83#define D2LOG_ALWAYS_S 0x80000
87namespace drama {
91 namespace logging {
93 /*
94 * We will have a map of the DRAMA context associated with each thread.
95 */
96 typedef std::map<std::thread::id, std::pair<std::string, Dits___CurActType>> DramaCtxMapType;
97 typedef DramaCtxMapType::iterator DramaCtxMapIter;
98 typedef DramaCtxMapType::const_iterator DramaCtxMapIterConst;
100 class Logger;
102 /*
103 * This object fetches and formats the time. The UpdateTime() function
104 * updates the internal time and TimeToString() returns the formated
105 * time string.
106 */
107 class LogTime {
108
109 private:
110 /*
111 * We keep about the formated time we last used - to avoid doing it
112 * again. We also need the time itself - for which we use a
113 * "long int" to avoid having to include time.h for this module.
114 */
115 long int _LastTime; // Last time we logged at
116 int _millisec; // milliseconds within the second
117 char _timeStr[30]; // Formated time string
119 // User specified offset to apply (for debugging)
120 static long int _s_userTimeOffset;
121
122 public:
123 LogTime();
124
125 /*
126 * Readout the current system time and update the internal time
127 * string. If altTime is non-zero, it is a pointer to a time to use
128 * instead of the current system time.
129 *
130 * If updateInternalTime is true, then the internal value kept for the
131 * last time is updated and the log file changed if appropiate.
132 * Otherwise only the string avialable to TimeString() is updated.
133 * We set this to false if we don't want to change the log file on a
134 * day change.
135 *
136 * day returns the current unix day (since 1 Jan 1970), but only
137 * if the time in seconds has changed in the last call, otherwise
138 * returns set to -1.
139 *
140 */
141 void UpdateTime(bool updateInternalTime,
142 int *day,
143 const IMP_AbsTime *altTime);
144
145 /*
146 * Force UpdateTime to re-read the time on the next read.
147 * This is necessary to force a fetch of the day.
148 */
149 void Reset() {
150 _LastTime = 0;
151 }
152
153 /*
154 * Return the time string.
155 */
156 const char *TimeString() const { return _timeStr; };
157
158 /*
159 * Return the time itself.
160 */
161 long GetTime() const { return _LastTime; };
162 /*
163 * Return the milliseconds point within the second.
164 */
165 int Millisec() const { return _millisec; };
166 /*
167 * Set/Get the current time offset.
168 */
169 static void SetTimeOffset(long int t) { _s_userTimeOffset = t; }
170 static long int GetTimeOffset() { return _s_userTimeOffset; }
171
172
173 ~LogTime();
174
175 }; // class LogTime
176
177 /* LogFileStream is a sub-class of std::ofstream which provides some
178 * special features around the type of file to be used for std::ofstream.
179 *
180 * In particular, it allows us to use a GCC file buffer, which allows
181 * us to to create a file buffer(NOT an iostream yet) from FILE *, so
182 * that we can:
183 *
184 * 1. Access the file descriptor (so we can sync the file to disk)
185 * 2. Wrap up access to a popen() call.
186 *
187 * This is currently GCC specific (what are we to do on the Macs?), but
188 * having these features in a class will allow us to isolate the changes
189 * needed.
190 *
191 * I found how to do this from
192 * http://www.unix.com/programming/151517-porting-ofstream-attach-linux-gcc.html
193 * Proper documentation at
194 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_io.html
195 *
196 * Might only work from libstdc++ 3.1 onwards. Need an equivalent
197 * for CLang (but haven't found one as of 21-May-2015.)
198 */
199 class LogFileStream : public std::ofstream {
200 private:
201#ifdef _DRAMA_HaveGnuFileBufExt
202 /*
203 * Pointer to the gcc stdio_filebuf() object. Non-portable
204 * code - may need to replace with other compilers, e.g. CLang.
205 */
206 std::unique_ptr<__gnu_cxx::stdio_filebuf<char> > _fileBuf;
207 /*
208 * A file pointer, being used when we open with popen().
209 */
210 FILE *_pFile = 0;
211#endif
212
213 public:
214 /* Constructor. Don't open the file with these */
215 LogFileStream() {}
216 /* Destructor */
217 ~LogFileStream();
218 /*
219 * Open the stream as the input to a command - using open().
220 */
221#ifdef _DRAMA_HaveGnuFileBufExt
222 void popen(const std::string &command);
223#endif
224 /*
225 * Open the stream to a file. This is provided so that we
226 * can implement fsync(), below.
227 */
228 void fopen(const std::string &filename);
229
230 /*
231 * Since the file to disk.
232 */
233 void fsync();
234
235 /*
236 * Close the file. Overrides ofstream::open();
237 * For some reason, override flag does not work here.
238 */
239 void close();
240
241#ifdef _DRAMA_HaveGnuFileBufExt
242 /*
243 * Indicate if the file is open. Override ofstream::is_open().
244 * For some reason, override flag does not work here.
245 */
246 bool is_open() const {
247 if (!_fileBuf) return false;
248 return _fileBuf->is_open();
249 }
250 /*
251 * Returns rdbuf - non-standard operation, but we need to override
252 * ofstream::rdbuf.
253 *
254 * For some reason, override flag does not work here.
255 */
256 __filebuf_type* rdbuf() const {
258 "Attempt to call LogBuffer::rdbuf");
259 }
260
261#endif
262
263
264 };
265
266 /*
267 * This class is used by Logger to ensure we have the correct
268 * DRAMA Context (Action/UFACE details) for the current thread.
269 * It is a friend of Logger, as it needs access to items the
270 * general public does not need.
271 *
272 * The constructor must work out if the current thread is the DRAMA
273 * main thread (that invoking RunDrama()) or an otherwise known thread.
274 * If the later, it must switch the DRAMA context to that of the known
275 * thread and reverse that effect when the destructor is run.
276 *
277 * This class implements the Resource Acquisition Is Initialization
278 * design pattern, but is intended to be used for Scope-based Resource
279 * Management only.
280 */
281 class GrabLogContext {
282 bool _onKnownThread = false;
283 bool _onCreateThread = false;
284 bool _onRunThread = false;
285 Dits___CurActType _entryContext;
286 std::string _func;
287 public:
288 GrabLogContext(const Logger &);
289 ~GrabLogContext();
290 // Returns true if this thread has a DRAMA context registered.
291 bool IsKnownThread() const {
292 return _onKnownThread;
293 }
294 // Returns true if this is the thread that created the DRAMA task.
295 bool IsDramaCreateThread() const {
296 return _onCreateThread;
297 }
298 // Returns true if this is the thread that run the DRAMA task.
299 bool IsDramaRunThread() const {
300 return _onRunThread;
301 }
302 // Returns the function name associated withe the thread.
303 std::string FuncName() const {
304 if (_onCreateThread)
305 return "";
306 if (_onRunThread) // No DRAMA creation thread, but am running DRAMA.
307 return "<<::RunDrama>>";
308 if (_onKnownThread)
309 return _func;
310 else
311 return "<<ukn thd fnc>>";
312 }
313 };
314
362 class LogStreamBuf : public std::streambuf {
363
364 private:
365 Logger *_theLogger;
366 std::string _prefix; // Log prefix string.
367 unsigned _level; // Log level we write at.
368
369 protected:
370 // Buffer for messages to output.
371 static const int BUFFER_SIZE = 200;
372 char _buffer[BUFFER_SIZE+1];
373
374 /*
375 * Buffer flush operation. returns number output.
376 */
377 int flushBuffer();
378 /*
379 * Invoked if adding a character would overflow the buffer.
380 * We Add it (since our constructor ensured there is sufficient
381 * space and then flush the buffer.
382 */
383 virtual int_type overflow(int_type c) override {
384 if (c != EOF)
385 {
386 // insert character into buffer
387 *pptr() = c;
388 pbump(1);
390 // flush the buffer
391 if (flushBuffer() == EOF)
392 {
393 // ERROR
394 return EOF;
395 }
396 return c;
397
398 }
399 /*
400 * Sync the file - just flushes to the log file.
401 */
402 virtual int sync() override {
403 if (flushBuffer() == EOF) {
404 // ERROR
405 return -1;
406 }
407 return 0;
408 }
409
410 // Was used for debugging.
411 //std::streamsize xsputn( const char_type* s, std::streamsize count ) override;
412
413
414 public:
421 LogStreamBuf(Logger *theLogger, unsigned level, const std::string &prefix) :
422 _theLogger(theLogger),
423 _prefix(prefix),
424 _level(level) {
425 /*
426 * Need to provide our buffer to the std::streambuf base
427 * class. One character less to ensure the last character
428 * causes an overflow.
429 */
430 setp(_buffer, _buffer+(BUFFER_SIZE-1));
431 }
432 void Debug(const char *where) {
433 fprintf(stderr, "LogStreamBuf(%s):object 0x%p, logger 0x%p, prefix %s, levels %u\n",
434 where, (void *)(this), (void *)(_theLogger), _prefix.c_str(), _level);
435 }
440 virtual ~LogStreamBuf() {
441 //fprintf(stderr,"******** LogStreamBuf destructor invoked object 0x%p *********\n", (void *)(this));
442 /*
443 * We want to output what is left, but any exception now
444 * (which may be caused by DRAMA failing to send the message
445 * for various reasons), if left uncaught, will cause the
446 * program to crash (can't throw from a destructor), so
447 * catch any DRAMA exception and use stderr.
448 */
449 try
450 {
451 sync();
452 }
453 catch (drama::Exception &e)
454 {
455 fprintf(stderr,"DRAMA Exception thrown by drama::~LogStreamBuf()\n");
456 fprintf(stderr,"%s\n", e.toString().c_str());
457 fprintf(stderr,"DRAMA Status = 0x%lX, %s\n",
458 static_cast<long int>(e.dramaStatus()),
459 e.dramaStatusStr().c_str());
460
461 }
462 }
463
464
471 LogStreamBuf(const LogStreamBuf &source) = delete;
472
481 LogStreamBuf& operator = (const LogStreamBuf &rhs) = delete;
482
489 LogStreamBuf(LogStreamBuf &&source) noexcept :
490 _theLogger(source._theLogger),
491 _prefix(source._prefix),
492 _level(source._level) {
493 source._theLogger = nullptr;
494 }
495
496
504 LogStreamBuf& operator=(LogStreamBuf &&rhs) noexcept {
505
506 this->_theLogger = rhs._theLogger;
507 this->_level = rhs._level;
508 this->_prefix = std::move(rhs._prefix);
509
510 rhs._theLogger = nullptr;
511 return *this;
512 }
513
514
515
516 }; //class LogStreamBuf
517
518#ifdef D2_PROVIDE_LOG_STREAM // Currently disabled. Does not work under CLang compiler, unclear why
519
520// LogStream not working under CLang, later versions. unclear why, but
521// appears related to copy/assignment. tocker would crash when
522// attempting to use a LogStream created by CreateLogStream() below.
523
551 class LogStream : public std::ostream {
552 friend class Logger;
553 private:
554 LogStreamBuf _buf;
555 /* Construct a LogStream object.
556 *
557 * Private since only normally constructed by the Logger object
558 * CreateLogStream() method.
559 *
560 * @param theLogger A pointer to the DRAMA logger object
561 * @param level The level at which the events will be written
562 * @param prefix The prefix for the log messages.
563 */
564 LogStream(Logger *theLogger, unsigned level, const std::string &prefix) :
565 _buf(theLogger, level, prefix) {
566 /*
567 * Set the buffer address for ostream.
568 */
569 rdbuf(&_buf);
570 }
571
572 public:
579 LogStream(const LogStream &source) = delete;
580
588 LogStream& operator = (const LogStream &rhs) = delete;
589
594 LogStream(LogStream &&source) noexcept : _buf(std::move(source._buf)){ }
595
596
601 LogStream& operator=(LogStream &&rhs) noexcept {
602
603 _buf = std::move(rhs._buf);
604 return *this;
605 }
606
607
608 }; //class LogStream.
609#endif
610
611
763 class Logger {
764
765 friend class GrabLogContext;
766 private:
767 /*
768 * This internal object is used to fetch and format the time.
769 */
770 LogTime _timer;
771
772
773 /* Structure used to maintain level names */
774 typedef struct {
775 int minsig; unsigned level; const char *string;
776 } LevelStruct;
777
778 /* Translations of various codes to strings */
779 static const LevelStruct _s_LevelNames[];
780 static const char *_s_RescheduleReasons[];
781 static const char *_s_Requests[];
782 static const char *_s_PathStatus[];
783 static const char *_s_MessageTypes[];
784
785 /* Maximum length of messages */
786 static const int _s_MsgLen;
787
788 /* Current Logging levels.*/
789 unsigned _currentLevels =
791
792
793 /*
794 * If we true,then logging of MsgOut messages is disabled. Used when
795 * we want to output something to the screen but not to the log file.
796 */
797 bool _disableMsgOut = false;
798
799 /* Log file stream and name. */
800 LogFileStream _logFile;
801 //std::ofstream _logFile;
802 std::string _logFileName;
803
804 /*
805 * LogDay contain the day number in the year. We use it to work
806 * out if the day has changed.
807 */
808 int _logDay = 0;
809
810 /*
811 * Pointer to the DRAMA task we are part of.
812 * The pointer is const - we never change it after the constructor.
813 * The task pointed to is NOT const - since we can operate on it.
814 */
815 Task * const _theTask;
816 /*
817 * Directory and system names supplied to constructor.
818 */
819 std::string _directory;
820 std::string _system;
821 /*
822 * Set true to always flush the log file.
823 */
824 bool _flushAlways = false;
825 /*
826 * Set true to turn of fsync() operation when flushing
827 */
828 bool _noFsync = false;
829 /*
830 * Set true to disable LogFlush()
831 */
832 bool _noLogFlush = false;
833 /*
834 * Set true when the log is flushed, cleared when messages
835 * are written.
836 */
837 bool _flushed = false;
838
839 /*
840 * Last write to log file failed.
841 */
842 bool _failed = false;
843 /*
844 * Are we compressing data on the fly)
845 */
846 bool _compress = false;
847 FILE *_compressFD = nullptr;
848 /*
849 * This variable records the approximate file size - in particular,
850 * the amount of data we have written to the file using
851 * Logger::LogMessage(), the core logging routine. It does not
852 * record various bits of header information.
853 *
854 * We use this allow us to create a new log file every 512 MB - to
855 * avoid file system file size problems which occur at about 1 GB on
856 * older file systems..
857 */
858 INT32 _fileSize = 0;
859
860 /*
861 * Should we add a column with the thread ID. This makes
862 * us incompatible with GIT Logger.
863 */
864 bool _logThreadID = false;
865 /*
866 * A MAP of thread to DRAMA context. Allows us to find the
867 * appropriate DRAMA context information for any registered
868 * thread - register threads with the RegisterThread() method.
869 */
870 DramaCtxMapType _threadToDRAMAContextMap;
871 /*
872 * The ID of the main thread - the one that created the logger
873 * (should be the thread running the DRAMA task).
874 */
875 std::thread::id _mainThreadId;
876 /*
877 * Used to actually sync the log file.
878 */
879 void SyncFile(const char *from_where);
880
881 /*
882 * We need a static routine to implement the log level action
883 * which can then call the object routine Action.
884 */
885 static void LogLevelAction(StatusType *status);
886 void Action(StatusType *status);
887
888 /*
889 * Methods supporting the constructor and the Open() method.
890 */
891 void CreateLogLevelAction(StatusType *status);
892 void CreateParameters(StatusType *status);
893 void InitialiseLogLevel(StatusType *status);
894 void LogTaskVersionInfo();
895
896 /*
897 * static routines which are passed to DRAMA to implement the
898 * DRAMA logging system. See DitsSetLogSys().
899 */
900 static DVOID ActionEntryLog(DVOIDP client_data,StatusType *status);
901 static DVOID ActionReturnLog(
903 int argDelete,
906 int delaySet,
910 static DVOID GetPathLog(
912 DCONSTV char * name,
913 DCONSTV char * node,
914 int flags,
916 DitsPathType path,
919 static DVOID MsgSendLog(
921 long int flags,
922 DitsPathType path,
926 static DVOID LoadLog(
928 DCONSTV char * Machine,
929 DCONSTV char * TaskName,
930 DCONSTV char * ArgString,
931 long int Flags,
935 static DVOID NotifyReqLog(
937 int notifyRequested,
938 DitsPathType path,
941 static DVOID MsgOutLog(
943 DCONSTV char * message,
945 static DVOID LogMsgLog(
947 unsigned level,
948 DCONSTV char * prefix,
949 DCONSTV char * fmt,
950 va_list ap,
952
953 static DVOID LogTrigger(
955 SdsIdType arg,
957
958 static DVOID LogTrigBulk(
961 int sds,
962 int NotifyBytes,
965
966 static DVOID LogSignal(
968 long int actptr,
969 DCONSTV DVOIDP ptr,
970 SdsIdType arg,
972
973 static DVOID LogBulkSend(
975 DCONSTV long int flags,
978 int NotifyBytes,
981 StatusType * status);
982
983
986 static DVOID LogShutdown(
988 int taskShutdown,
990
991 static DVOID LogFlush(DVOIDP client_data, StatusType *status);
992 static DVOID LogInfo(DVOIDP client_data, StatusType *status);
993
994
995 /*
996 * The actual routine which logs to the file etc. If altTime is
997 * specified, then the log message is taged with that time, otherwise
998 * it is tagged with the current time
999 */
1000 void LogMessage(const char *prefix,
1001 const char *message,
1002 const IMP_AbsTime *altTime=0);
1003
1004
1005 /*
1006 * Methods to set the logging levels from a string.
1007 */
1008 void SetLevels(const std::string &s, StatusType *status);
1009
1010 /* Methods to fetch logging levels. */
1011 std::string GetLevels() const;
1012
1013 /* Support function for GetLevels */
1014 void LevelCheckAndAdd(unsigned index, std::string *s) const;
1015
1016 void OpenLogFile(bool day_rollover, bool size);
1017 void OpenIt(const std::string &BaseLogFileName);
1018 /* Check if the file size has got too large */
1019 void CheckFileSize();
1020
1021 /* Check if we should use compress mode */
1022 void CheckCompressMode();
1023 /* Close log file */
1024 void CloseLogFile();
1025
1026 /* Create a new log file name */
1027 static std::string NewName(const std::string &BaseLogFileName, int counter);
1028
1029 /* Has a log file named already been used */
1030 static bool NameUsed(const std::string &name);
1031
1032 /* Check if the day has changed. If it has, reopen the log file for
1033 * the new day.
1034 */
1035 void CheckDayChange(int newDay);
1036
1037 /*
1038 * Assignment operation and Copy constructor deleted
1039 * to avoid misuse.
1040 */
1041 void operator=(const Logger&) = delete;
1042 Logger(const Logger&) = delete;
1043
1044
1045 /*
1046 * A class used to temporally disable MsgOut logging.
1047 *
1048 * This class implements the Resource Acquisition Is Initialization
1049 * design pattern, but is intended to be used for Scope-based Resource
1050 * Management only.
1051 */
1052 class MsgOutNoLog {
1053 private:
1054 Logger *_theLogger;
1055 bool _previousState;
1056 public:
1057 MsgOutNoLog(Logger *theLogger) :
1058 _theLogger(theLogger),
1059 _previousState(theLogger->_disableMsgOut) {
1060 theLogger->_disableMsgOut = true;
1061 }
1062 ~MsgOutNoLog() {
1063 _theLogger->_disableMsgOut = _previousState;;
1064 }
1065 };
1066
1067 public:
1068
1082 Logger(Task * dramaTask);
1102 void Open(const std::string &system,
1103 const std::string &dir="",
1104 bool compress=false);
1105
1106
1115 ~Logger();
1116
1117
1118
1127 static void SetTimeOffset(long int t){LogTime::SetTimeOffset(t); }
1128
1144 void Log(unsigned level, bool nofmt, const char *prefix,
1145 const char *fmt, ...)
1146#ifdef __GNUC__
1147 __attribute__ ((format (printf, 5, 6))) /* Note, method version of __attribute__ needs 1 added to each argument over non-method version. */
1148#endif
1149 ;
1150
1151
1172 template<typename... Types>
1173 void SLog(unsigned level, const std::string &prefix,
1174 const std::string &fmt, Types... args) {
1175 /*
1176 * Our approach is to write the output to a string, via
1177 * SafePrintf(), then output that in one operation.
1178 */
1179 std::stringstream sstrm;
1180 drama::SafePrintf(sstrm, fmt.c_str(), args...);
1181 DGCC_DIAG_OFF(format-security) // Since formating disabled, no problem
1182 Log(level, true, prefix.c_str(), sstrm.str().c_str());
1184
1185 }
1213 template<typename... Types>
1214 void SLog( std::ostream &ostream,
1215 unsigned level, const std::string &prefix,
1216 const std::string &fmt, Types... args) {
1217 /*
1218 * Our approach is to write the output to a string, via
1219 * SafePrintf(), then output that in one operation.
1220 */
1221 std::stringstream sstrm;
1222 drama::SafePrintf(sstrm, fmt.c_str(), args...);
1223 Log(level, true, prefix.c_str(), sstrm.str().c_str());
1224
1225 ostream << sstrm.str() << std::endl;
1226 }
1227
1254 void Log(const IMP_AbsTime *time,
1255 unsigned level, bool nofmt, const char *prefix,
1256 const char *fmt, ...)
1257#ifdef __GNUC__
1258 __attribute__ ((format (printf, 6, 7)))
1259#endif
1260 ;
1261
1267 void Set(unsigned newLevels);
1268
1274 void Unset(unsigned disableLevels);
1275
1298 std::thread::id threadId=std::this_thread::get_id(),
1299 const char* func = "*unnamed func*");
1319 void RegisterThread(std::thread::id threadId=std::this_thread::get_id(),
1320 const char* func = "*unamed func*");
1321
1322
1346 void RegisterThread(std::thread::id sourceThread,
1347 std::thread::id newThread,
1348 const char* func = "*unnamed func*");
1349
1350
1351
1366 std::weak_ptr<Task> dramaTask,
1367 const char* func = "*non-drama*");
1368
1377 Task * GetTask() {
1378 return _theTask;
1379 }
1380
1381#ifdef D2_PROVIDE_LOG_STREAM // Currently disabled.
1382// Not working under CLANG - Mac ElCapitan and Serria.
1383// Problem with copy/assignment in LogStream!!!! (I think).
1402 LogStream CreateLogStream(unsigned level,
1403 const std::string &prefix) {
1404 return LogStream(this, level, prefix);
1405 }
1406
1407
1408
1409#endif
1410
1411 }; // class Logger
1412
1413
1414
1415
1416 } // namespace logging
1417
1418} // namespace drama
1419
1420#endif
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:162
A class which implements a DRAMA task.
Definition task.hh:446
LogStreamBuf & operator=(LogStreamBuf &&rhs) noexcept
Move assignment operator.
Definition logger.hh:531
LogStreamBuf(Logger *theLogger, unsigned level, const std::string &prefix)
Construct a LogStreamBuf object.
Definition logger.hh:448
LogStreamBuf(const LogStreamBuf &source)=delete
Copy constructor - deleted.
virtual ~LogStreamBuf()
Destroy the LogStreamBuf, any remaining output is sent.
Definition logger.hh:467
LogStreamBuf(LogStreamBuf &&source) noexcept
Move copy constructor.
Definition logger.hh:516
LogStreamBuf & operator=(const LogStreamBuf &rhs)=delete
Assignment operator - deleted.
Implement a streambuf sub-class that can write messages via the DRAMA Logger interface.
Definition logger.hh:389
void Set(unsigned newLevels)
Enable new logging levels.
void RegisterThread(const Dits___CurActType &dramaContext, std::thread::id threadId=std::this_thread::get_id(), const char *func="*unnamed func*")
Register the DRAMA context of a thread.
void RegisterThread(std::thread::id threadId=std::this_thread::get_id(), const char *func="*unamed func*")
Register the current DRAMA context against a thread.
void RegisterThread(std::thread::id sourceThread, std::thread::id newThread, const char *func="*unnamed func*")
Register the DRAMA context of one thread against a new thread.
static void SetTimeOffset(long int t)
Change the time offset.
Definition logger.hh:1154
void SLog(std::ostream &ostream, unsigned level, const std::string &prefix, const std::string &fmt, Types... args)
Log a message using type safe formatting and output to a stream.
Definition logger.hh:1241
void SLog(unsigned level, const std::string &prefix, const std::string &fmt, Types... args)
Log a message using type safe formatting.
Definition logger.hh:1200
Logger(Task *dramaTask)
Construct a drama::logging::Logger object.
void Open(const std::string &system, const std::string &dir="", bool compress=false)
Open the log file.
void Log(const IMP_AbsTime *time, unsigned level, bool nofmt, const char *prefix, const char *fmt,...)
Log a message with a specified event time.
void Unset(unsigned disableLevels)
Clear particular logging levels.
Task * GetTask()
Return the DRAMA task associated with the logger.
Definition logger.hh:1404
void Log(unsigned level, bool nofmt, const char *prefix, const char *fmt,...)
Log a message using C printf formating.
void RegisterThreadNoDramaCtx(std::weak_ptr< Task > dramaTask, const char *func="*non-drama*")
Register this thread with with the logger, but without a DRAMA context.
Implementation of a Class supporting Logging within an AAO DRAMA Task.
Definition logger.hh:790
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:87
#define D2LOG_ALWAYS
Always log the message.
Definition logger.hh:109
#define D2LOG_ALWAYS_S
Always log the messages, including to the screen.
Definition logger.hh:110
#define D2LOG_ERRORS
Log Ers and action completion errors.
Definition logger.hh:94
#define D2LOG_MSG
Log MsgOut messages.
Definition logger.hh:98
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1327
void SafePrintf(std::ostream &ostream, const char *str)
Safe formatted write to a stream.
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93