Belle II Software  release-08-01-10
LogFile.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #ifndef _Belle2_LogFile_h
9 #define _Belle2_LogFile_h
10 
11 #include <daq/slc/system/Mutex.h>
12 
13 #include <daq/slc/base/Date.h>
14 
15 #include <string>
16 #include <fstream>
17 #include <stdarg.h>
18 
19 namespace Belle2 {
25  struct LogFile {
26 
27  public:
28  enum Priority {
29  UNKNOWN = 0, DEBUG, INFO, NOTICE, WARNING, ERROR, FATAL
30  };
31 
32  public:
33  static Priority getPriority(const std::string& str);
34 
35  private:
36  LogFile() {}
37  ~LogFile() {}
38 
39  private:
40  static bool g_stderr;
41  static bool g_opened;
42  static std::string g_filepath;
43  static std::string g_linkpath;
44  static std::ofstream g_stream;
45  static unsigned int g_filesize;
46  static Mutex g_mutex;
47  static Priority g_threshold;
48  static std::string g_filename;
49  static Date g_date;
50 
51  // member functions
52  public:
53  static void open(const std::string& filename,
54  Priority priority = UNKNOWN);
55  static void open();
56  static void close();
57  static void debug(const std::string& msg, ...);
58  static void info(const std::string& msg, ...);
59  static void notice(const std::string& msg, ...);
60  static void warning(const std::string& msg, ...);
61  static void error(const std::string& msg, ...);
62  static void fatal(const std::string& msg, ...);
63  static void put(Priority priority, const std::string& msg, ...);
64  static void setStdErr(bool stdErr)
65  {
66  g_stderr = stdErr;
67  }
68 
69  private:
70  static int put_impl(const std::string& msg, Priority priority, va_list ap);
71 
72  };
73 
75 };
76 
77 #endif
Abstract base class for different kinds of events.