ROOT logo
// $Id: ZLog.h 2743 2012-04-26 19:17:02Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

#ifndef GledCore_ZLog_H
#define GledCore_ZLog_H

#include <Glasses/ZGlass.h>

#include <Gled/GCondition.h>
#include <Gled/GTime.h>

#include <fstream>
#include <stdarg.h>

class GThread;


class ZLog : public ZGlass
{
  MAC_RNR_FRIENDS(ZLog);

public:
  enum Level_e
  {
    L_Fatal, L_Error, L_Warning, L_Message, L_Info, L_Debug
  };

  class Helper
  {
    ZLog    *m_log;
    GTime    m_time;
    TString  m_time_string;
    TString  m_prefix;
    Int_t    m_level;

  public:
    Helper(ZLog* log, const TString& pfx="");
    Helper(ZLog* log, Int_t lvl, const TString& pfx="");
    Helper(ZLog* log, const GTime& when, const TString& pfx="");
    Helper(ZLog* log, const GTime& when, Int_t lvl, const TString& pfx="");

    void SetTime(const GTime& time);

    void Put(const TString& message);
    void Put(Int_t level, const TString& message);

    void Form(const char* fmt, ...);
    void Form(Int_t level, const char* fmt, ...);

    // ostream& operator<<();
  };

  struct Message
  {
    GTime   m_when;
    TString m_prefix;
    TString m_message;
    Int_t   m_level;
  };

private:
  void _init();

protected:
  TString           mFileName;     // X{GS} 7 Textor()
  Level_e           mLevel;        // X{GS} 7 PhonyEnum()
  Int_t             mDebugLevel;   // X{GS} 7 Value(-range=>[0, 9, 1])
  Bool_t            bLogActive;    // X{G}  7 BoolOut()

  GCondition        mLoggerCond;   //!
  GThread          *mLoggerThread; //!
  ofstream          mStream;       //!

  static void tl_LogLoop(ZLog* log);
  void   LogLoop();

public:
  ZLog(const Text_t* n="ZLog", const Text_t* t=0);
  virtual ~ZLog();

  void StartLogging(); // X{Ed} 7 MButt()
  void StopLogging();  // X{Ed} 7 MButt()

  void RotateLog();    // X{Ed} 7 MButt()

  // void ReopenFile();   // X{E}

  void Put(Int_t level, const TString& prefix, const TString& message);
  void Put(const GTime&   time,        Int_t level, const TString& prefix, const TString& message);
  void Put(const TString& time_string, Int_t level, const TString& prefix, const TString& message);

  void Form(Int_t level, const TString& prefix, const char* fmt, ...);
  void Form(const GTime&   time,        Int_t level, const TString& prefix, const char* fmt, ...);
  void Form(const TString& time_string, Int_t level, const TString& prefix, const char* fmt, ...);
  // #if defined(__GNUC__) && !defined(__CINT__)
  //    __attribute__((format(printf, 1, 2)))
  // #endif
  // ; // This is in TString. Probably compile-time checks -- good!

  void FormVA(const GTime&   time,        Int_t level, const TString& prefix, const char* fmt, va_list args);
  void FormVA(const TString& time_string, Int_t level, const TString& prefix, const char* fmt, va_list args);

  // ostream& operator()(Int_t level);
  // ostream& operator()(Int_t level, const GTime& time);

#include "ZLog.h7"
  ClassDef(ZLog, 1);
}; // endclass ZLog

#endif
 ZLog.h:1
 ZLog.h:2
 ZLog.h:3
 ZLog.h:4
 ZLog.h:5
 ZLog.h:6
 ZLog.h:7
 ZLog.h:8
 ZLog.h:9
 ZLog.h:10
 ZLog.h:11
 ZLog.h:12
 ZLog.h:13
 ZLog.h:14
 ZLog.h:15
 ZLog.h:16
 ZLog.h:17
 ZLog.h:18
 ZLog.h:19
 ZLog.h:20
 ZLog.h:21
 ZLog.h:22
 ZLog.h:23
 ZLog.h:24
 ZLog.h:25
 ZLog.h:26
 ZLog.h:27
 ZLog.h:28
 ZLog.h:29
 ZLog.h:30
 ZLog.h:31
 ZLog.h:32
 ZLog.h:33
 ZLog.h:34
 ZLog.h:35
 ZLog.h:36
 ZLog.h:37
 ZLog.h:38
 ZLog.h:39
 ZLog.h:40
 ZLog.h:41
 ZLog.h:42
 ZLog.h:43
 ZLog.h:44
 ZLog.h:45
 ZLog.h:46
 ZLog.h:47
 ZLog.h:48
 ZLog.h:49
 ZLog.h:50
 ZLog.h:51
 ZLog.h:52
 ZLog.h:53
 ZLog.h:54
 ZLog.h:55
 ZLog.h:56
 ZLog.h:57
 ZLog.h:58
 ZLog.h:59
 ZLog.h:60
 ZLog.h:61
 ZLog.h:62
 ZLog.h:63
 ZLog.h:64
 ZLog.h:65
 ZLog.h:66
 ZLog.h:67
 ZLog.h:68
 ZLog.h:69
 ZLog.h:70
 ZLog.h:71
 ZLog.h:72
 ZLog.h:73
 ZLog.h:74
 ZLog.h:75
 ZLog.h:76
 ZLog.h:77
 ZLog.h:78
 ZLog.h:79
 ZLog.h:80
 ZLog.h:81
 ZLog.h:82
 ZLog.h:83
 ZLog.h:84
 ZLog.h:85
 ZLog.h:86
 ZLog.h:87
 ZLog.h:88
 ZLog.h:89
 ZLog.h:90
 ZLog.h:91
 ZLog.h:92
 ZLog.h:93
 ZLog.h:94
 ZLog.h:95
 ZLog.h:96
 ZLog.h:97
 ZLog.h:98
 ZLog.h:99
 ZLog.h:100
 ZLog.h:101
 ZLog.h:102
 ZLog.h:103
 ZLog.h:104
 ZLog.h:105
 ZLog.h:106
 ZLog.h:107
 ZLog.h:108
 ZLog.h:109
 ZLog.h:110
 ZLog.h:111
 ZLog.h:112
 ZLog.h:113