Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:33

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 #include <JANA/JLogger.h> 
0018 // Quick-and-dirty cyclic dependency to ensure that jout/jerr are
0019 // provided regardless of whether JLogger.h or JStreamLog.h is included
0020 
0021 /// JStreamLog provides an interface for for writing messages
0022 /// in a way that buffers them by thread to prevent multiple
0023 /// threads from simultaneously writing to the screen (via
0024 /// cout and cerr) causing the characters to intermix resulting
0025 /// in gibberish.
0026 ///
0027 /// JANA using the jout and jerr global streams by default which
0028 /// send their output to cout and cerr respectively. In addition,
0029 /// they can optionally prepend a special "tag" string to indicate
0030 /// which stream the message came from. By default, these are 
0031 /// set to "JANA >>" and "JANA ERROR>>", but are user configureable.
0032 /// One can also turn on prepending of timestamps to be printed
0033 /// with each line (this is off by default).
0034 ///
0035 /// JStreamLog objects inherit from std::ostream and so can be used
0036 /// just like cout and cerr.
0037 ///
0038 /// Example:
0039 ///
0040 ///    jout<<"Hello World!"<<endl;
0041 ///
0042 
0043 class [[deprecated("JStreamLog will be replaced by JLogger in the next release.")]] JStreamLog : public std::ostream
0044 {
0045     public:
0046         JStreamLog(const std::ostream& os=std::cout, const char* tag="INFO");
0047         JStreamLog(const std::ostream& os, const std::string& tag);
0048         JStreamLog(std::streambuf* buf, const char* tag);
0049         virtual ~JStreamLog();
0050 
0051         std::string GetTag(void);
0052         bool GetTimestampFlag(void);
0053         bool GetThreadstampFlag(void);
0054         JStreamLogBuffer* GetJStreamLogBuffer(void);
0055         void SetTag(std::string tag);
0056         void SetTimestampFlag(bool prepend_timestamp=true);
0057         void SetThreadstampFlag(bool prepend_threadstamp=true);
0058 
0059     private:
0060         bool own_rdbuf; // keep track if we deleted the buffer object already
0061 };
0062 
0063 std::ostream& endMsg(std::ostream& os);
0064 
0065 
0066 
0067