メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TSystemLogging.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TSystemLogging.cc,v 1.7 2004/06/24 15:15:26 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TSystemLogging.cc,v $
00005 //  Revision 1.7  2004/06/24 15:15:26  goiwai
00006 //  たくさんの変更
00007 //  Tcout,Tcerr,Tlogをバッファ経由にした。
00008 //  何個かexternした。Tlog,Tcout,Tcerr,Tinfo...Tcritなど出力関係。
00009 //
00010 //  Revision 1.6  2004/03/07 10:30:34  goiwai
00011 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00012 //  全てにおいて完全に動作するわけではありません。
00013 //
00014 //  Revision 1.5  2003/12/06 10:13:51  goiwai
00015 //  TSystemLogging& operator=() -> const TSystemLogging& operator=()
00016 //  に変更しました.
00017 //
00018 //  Revision 1.4  2003/12/04 23:19:52  goiwai
00019 //  システムロガーにメッセージ送信するための部品です.
00020 //  ここでexternするとリンクできないといって怒られるので
00021 //  Tsyslog.hというファイルでextern宣言しています.
00022 //
00023 //  Revision 1.3  2003/10/06 16:38:26  goiwai
00024 //  *** empty log message ***
00025 //
00026 //  Revision 1.2  2003/07/30 16:21:21  goiwai
00027 //  ファイルにコミットログをつけることにしました.
00028 //
00029 // =====================================================================
00030 #include "TSystemLogging.hh"
00031 
00032 TSystemLogging::TSystemLogging( Tint level, Tint facility, Tint option )
00033   : theLevel( level ), 
00034     theFacility( facility ), 
00035     theOption( option ),
00036     theID(),
00037     theMessageBuffer()
00038 {
00039   SetID();
00040 }
00041 
00042 TSystemLogging::TSystemLogging( const TSystemLogging& right )
00043   : theLevel( right.theLevel ), 
00044     theFacility( right.theFacility ), 
00045     theOption( right.theOption ),
00046     theID(),
00047     theMessageBuffer( right.theMessageBuffer )
00048 {
00049   SetID();
00050 }
00051 
00052 TSystemLogging::~TSystemLogging()
00053 {
00054   Close();
00055 }
00056 
00057 Tvoid TSystemLogging::Open( Tint option, Tint facility )
00058 {
00059   SetOption( option );
00060   SetFacility( facility );
00061   Open();
00062   return;
00063 }
00064 
00065 Tvoid TSystemLogging::Open( Tint option )
00066 {
00067   SetOption( option );
00068   Open();
00069   return;
00070 }
00071 
00072 Tvoid TSystemLogging::Open()
00073 {
00074   openlog( theID.c_str(), theOption, theFacility );
00075   return;
00076 }
00077 
00078 Tvoid TSystemLogging::Close()
00079 {
00080   closelog();
00081   return;
00082 }
00083 
00084 Tvoid TSystemLogging::Record( Tint level, const Tstring& format, ... )
00085 {
00086   va_list ap;
00087   va_start( ap,&format );
00088   va_end(ap);
00089   Record( level, format, ap );
00090   return;
00091 }
00092 
00093 Tvoid TSystemLogging::Record( const Tstring& format, ...)
00094 {
00095   va_list ap;
00096   va_start(ap,&format);
00097   va_end(ap);
00098   Record(format,ap);
00099   return;
00100 }
00101 
00102 Tvoid TSystemLogging::Record( Tint level, const Tstring& format, va_list ap )
00103 {
00104   SetLevel(level);
00105   Record(format,ap);
00106   return;
00107 }
00108 
00109 Tvoid TSystemLogging::Record( const Tstring& format, va_list ap )
00110 {
00111   Open();
00112   vsyslog(theLevel|theFacility,format.c_str(),ap);
00113   Close();
00114   return;
00115 }
00116 
00117 Tvoid TSystemLogging::SetID()
00118 {
00119   static const Tstring _EMERG_ID = "CLDAQ:EMERG";
00120   static const Tstring _ALERT_ID = "CLDAQ:ALERT";
00121   static const Tstring _CRIT_ID = "CLDAQ:CRIT";
00122   static const Tstring _ERROR_ID = "CLDAQ:ERROR";
00123   static const Tstring _WARNING_ID = "CLDAQ:WARNING";
00124   static const Tstring _NOTICE_ID = "CLDAQ:NOTICE";
00125   static const Tstring _INFO_ID = "CLDAQ:INFO";
00126   static const Tstring _DEBUG_ID = "CLDAQ:DEBUG";
00127  
00128   switch ( theLevel ) {
00129     case EMERG:
00130       theID = _EMERG_ID;
00131       break;
00132     case ALERT:
00133       theID = _ALERT_ID;
00134       break;
00135     case CRIT:
00136       theID = _CRIT_ID;
00137       break;
00138     case ERROR:
00139       theID = _ERROR_ID;
00140       break;
00141     case WARNING:
00142       theID = _WARNING_ID;
00143       break;
00144     case NOTICE:
00145       theID = _NOTICE_ID;
00146       break;
00147     case INFO:
00148       theID = _INFO_ID;
00149       break;
00150     case DEBUG:
00151       theID = _DEBUG_ID;
00152       break;
00153     default:
00154       theID = _INFO_ID;
00155       break;
00156   }
00157   return;
00158 }
00159 
00160 const TSystemLogging& TSystemLogging::operator=( const TSystemLogging& right )
00161 {
00162   theLevel = right.theLevel;
00163   theFacility = right.theFacility;
00164   theOption = right.theOption;
00165   SetID();
00166   theMessageBuffer = right.theMessageBuffer;
00167   return *this;
00168 }
00169 
00170 TSystemLogging& TSystemLogging::operator<<( Tint* n )
00171 {
00172   static const Tint buflen = 16;
00173   static Tchar buf[ buflen ];
00174   Tostrstream os( buf, buflen );
00175   os << n << Tflush;
00176   Tstring s = os.str();
00177   return *this << s;
00178 }
00179 
00180 TSystemLogging& TSystemLogging::operator<<( Tostream& (*pf)(Tostream&) )
00181 {
00182   Record( theMessageBuffer );
00183   switch ( theLevel ) {
00184     case EMERG:
00185     case ALERT:
00186       Tcerr << theMessageBuffer << pf;
00187       exit( EXIT_FAILURE );
00188       break;
00189     case CRIT:
00190       Tcerr << theMessageBuffer << pf;
00191       exit( EXIT_SUCCESS );
00192       break;
00193     case ERROR:
00194       Tcerr << theMessageBuffer << pf;
00195       break;
00196     case WARNING:
00197     case NOTICE:
00198     case INFO:
00199     case DEBUG:
00200     default:
00201       Tcout << theMessageBuffer << pf;
00202       break;
00203   }
00204   ClearBuffer();
00205   return *this;
00206 }
00207 
00208 TSystemLogging Temerg( TSystemLogging::EMERG );
00209 TSystemLogging Talert( TSystemLogging::ALERT );
00210 TSystemLogging Tcrit( TSystemLogging::CRIT );
00211 TSystemLogging Terror( TSystemLogging::ERROR );
00212 TSystemLogging Twarn( TSystemLogging::WARNING );
00213 TSystemLogging Tnotice( TSystemLogging::NOTICE );
00214 TSystemLogging Tinfo( TSystemLogging::INFO );
00215 TSystemLogging Tdebug( TSystemLogging::DEBUG );
00216 
00217 #ifdef __CLDAQ_ROOT_DLL
00218     ClassImp(TSystemLogging)
00219 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp