File: fglogger.h

package info (click to toggle)
ftpgrab 0.1.2r-9.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 380 kB
  • ctags: 335
  • sloc: cpp: 2,798; makefile: 26
file content (83 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef _FGLOGGER_H
#define _FGLOGGER_H

// fglogger.h
// Simple class encapsulating the event logger

#ifndef _FGSTRING_H
#include "fgstring.h"
#endif

// Fun and games!!
struct _IO_FILE;
typedef struct _IO_FILE FILE;

class FGException;

class FGLogger {
public:
  // Enum of log severities
  enum EFGLogSeverity {
    kFGLLDebug = 1,
    kFGLLVerbose,
    kFGLLInfo,
    kFGLLWarn,
    kFGLLErr,
    kFGLLBadNews
  };

  // To shut up some warnings
  FGLogger();

  // The all important methods to log things
  void LogMsg(const FGString& msg, EFGLogSeverity severity,
              bool locked = false);
  void LogException(const FGException& e, bool locked = false);

  // Method to access the logger object - singleton pattern
  static FGLogger& GetLogger(void);

  // To set the log file name
  static void SetLogName(const FGString& name);

  // Special lock methods for client activity that needs to guarantee
  // sequentially logged messages appear uninterrupted by other thread
  // logging activity
  static void Lock(void);
  static void Unlock(void);

private:
  // Banned!
  FGLogger(const FGLogger& other);
  FGLogger& operator=(const FGLogger& other);

  // Construct the logger
  FGLogger(const FGString& fileName);

  // The actual log instance
  static FGLogger* mspLogger;

  // The filename to log to - must be set before first call to
  // GetLogger()
  static FGString msFileName;

  // Internal methods
  FGString GetDateStamp(void) const;

  // Stream we are logging to
  FILE* mpFile;

  // Helper classes
  // Urgh. Can't forward declare pthread_mutex_t => use of void*
  class MutexAutoUnlocker
  {
  public:
    MutexAutoUnlocker();
    void Prime(void* pMutex);
    ~MutexAutoUnlocker();
  private:
    void* mpMutex;
  };
};

#endif // _FGLOGGER_H