Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 #include <pthread.h>
0003 
0004 //using namespace std;
0005 
0006 #include "JStreamLog.h"
0007 
0008 JStreamLog::JStreamLog(std::streambuf* buf, const char* tag) : std::ostream(new JStreamLogBuffer(buf, tag)), own_rdbuf(true)
0009 {}
0010 
0011 JStreamLog::JStreamLog(const std::ostream& os, const char* tag) : std::ostream(new JStreamLogBuffer(os.rdbuf(), tag)), own_rdbuf(true)
0012 {}
0013 
0014 JStreamLog::JStreamLog(const std::ostream& os, const std::string& tag) : std::ostream(new JStreamLogBuffer(os.rdbuf(), tag.c_str())), own_rdbuf(true)
0015 {}
0016 
0017 JStreamLog::~JStreamLog() {
0018     // On some Linux systems (CentOS 6.4) it seems this destructor
0019     // is called twice whenever a plugin is attached. I can only guess
0020     // that the global-scope jout and jerr are somehow linked when
0021     // the plugin is attached, but their destructors are called both
0022     // when they are detached and when the program exists. The problem
0023     // manifests in a seg. fault at the very end of the program. To avoid
0024     // this, we keep a flag that is set in the constructor and cleared
0025     // here in the destructor to indicate that the JStreamLogBuffer has
0026     // been deleted already. Thus, we don't try deleting it a second time
0027     // and therefore avoid the seg. fault.    Dec. 13, 2013  D.L.
0028     if(own_rdbuf){
0029         std::streambuf *mybuf = rdbuf(NULL);
0030         if(mybuf!=NULL) delete mybuf;
0031     }
0032     own_rdbuf = false;
0033 }
0034 
0035 std::ostream& endMsg(std::ostream& dSL) {
0036     dSL << static_cast<char>(6);
0037     dSL << std::flush;
0038     return dSL;
0039 }
0040 
0041 //------------------
0042 // GetTag
0043 //------------------
0044 std::string JStreamLog::GetTag(void)
0045 {
0046     JStreamLogBuffer *b = GetJStreamLogBuffer();
0047 
0048     return (b ? b->GetTag():"unknown");
0049 }
0050 
0051 //------------------
0052 // GetTimestampFlag
0053 //------------------
0054 bool JStreamLog::GetTimestampFlag(void)
0055 {
0056     JStreamLogBuffer *b = GetJStreamLogBuffer();
0057 
0058     return (b ? b->GetTimestampFlag():false);
0059 }
0060 
0061 //------------------
0062 // GetThreadstampFlag
0063 //------------------
0064 bool JStreamLog::GetThreadstampFlag(void)
0065 {
0066     JStreamLogBuffer *b = GetJStreamLogBuffer();
0067 
0068     return (b ? b->GetThreadstampFlag():false);
0069 }
0070 
0071 //------------------
0072 // SetTag
0073 //------------------
0074 void JStreamLog::SetTag(std::string tag)
0075 {
0076     JStreamLogBuffer *b = GetJStreamLogBuffer();
0077     if(b)b->SetTag(tag);
0078 }
0079 
0080 //------------------
0081 // SetTimestampFlag
0082 //------------------
0083 void JStreamLog::SetTimestampFlag(bool prepend_timestamp)
0084 {
0085     JStreamLogBuffer *b = GetJStreamLogBuffer();
0086     if(b)b->SetTimestampFlag(prepend_timestamp);
0087 }
0088 
0089 //------------------
0090 // SetThreadstampFlag
0091 //------------------
0092 void JStreamLog::SetThreadstampFlag(bool prepend_threadstamp)
0093 {
0094     JStreamLogBuffer *b = GetJStreamLogBuffer();
0095     if(b)b->SetThreadstampFlag(prepend_threadstamp);
0096 }
0097 
0098 //------------------
0099 // GetJStreamLogBuffer
0100 //------------------
0101 JStreamLogBuffer* JStreamLog::GetJStreamLogBuffer(void)
0102 {
0103     // Try and dynamic cast our streambuf as a JStreamLogBuffer
0104     return dynamic_cast<JStreamLogBuffer*> (rdbuf());
0105 }
0106 
0107