Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:26

0001 //*************************************************************
0002 // JStreamLog.h - Header file for stream-based logging.
0003 // Author:  Craig Bookwalter
0004 // Date:    Aug 2005
0005 // Notes:   Much of this was derived from examples given by
0006 //  D. Kuehl at http://www.inf.uni-konstanz.de/~kuehl/iostream/
0007 //  Also, many thanks to J. Hardie for his assistance with 
0008 //  obscure protected-member rules. 
0009 //*************************************************************
0010 
0011 #pragma once
0012 #include <iostream>
0013 #include <fstream>
0014 #include <string>
0015 #include "JStreamLogBuffer.h"
0016 
0017 /// JStreamLog provides an interface for for writing messages
0018 /// in a way that buffers them by thread to prevent multiple
0019 /// threads from simultaneously writing to the screen (via
0020 /// cout and cerr) causing the characters to intermix resulting
0021 /// in gibberish.
0022 ///
0023 /// JANA using the jout and jerr global streams by default which
0024 /// send their output to cout and cerr respectively. In addition,
0025 /// they can optionally prepend a special "tag" string to indicate
0026 /// which stream the message came from. By default, these are 
0027 /// set to "JANA >>" and "JANA ERROR>>", but are user configureable.
0028 /// One can also turn on prepending of timestamps to be printed
0029 /// with each line (this is off by default).
0030 ///
0031 /// JStreamLog objects inherit from std::ostream and so can be used
0032 /// just like cout and cerr.
0033 ///
0034 /// Example:
0035 ///
0036 ///    jout<<"Hello World!"<<endl;
0037 ///
0038 
0039 class JStreamLog : public std::ostream
0040 {
0041     public:
0042         JStreamLog(const std::ostream& os=std::cout, const char* tag="INFO");
0043         JStreamLog(const std::ostream& os, const std::string& tag);
0044         JStreamLog(std::streambuf* buf, const char* tag);
0045         virtual ~JStreamLog();
0046 
0047         std::string GetTag(void);
0048         bool GetTimestampFlag(void);
0049         bool GetThreadstampFlag(void);
0050         JStreamLogBuffer* GetJStreamLogBuffer(void);
0051         void SetTag(std::string tag);
0052         void SetTimestampFlag(bool prepend_timestamp=true);
0053         void SetThreadstampFlag(bool prepend_threadstamp=true);
0054 
0055     private:
0056         bool own_rdbuf; // keep track if we deleted the buffer object already
0057 };
0058 
0059 std::ostream& endMsg(std::ostream& os);
0060 
0061 extern JStreamLog jout;
0062 extern JStreamLog jerr;
0063 #define jendl std::endl
0064 
0065 #define _DBG_ std::cerr<<__FILE__<<":"<<__LINE__<<" "
0066 #define _DBG__ std::cerr<<__FILE__<<":"<<__LINE__<<std::endl
0067 
0068