A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PDBLogger.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 /*
20  * File: PDBLogger.h
21  * Author: Chris
22  *
23  * Created on September 26, 2015, 7:39 AM
24  */
25 
26 #ifndef PDBLOGGER_H
27 #define PDBLOGGER_H
28 
29 #include <memory>
30 #include "LogLevel.h"
31 
32 #include <pthread.h>
33 
34 
35 // used to log client and server activity to a text file
36 
37 namespace pdb {
38 
39 // create a smart pointer for PDBLogger objects
40 class PDBLogger;
41 typedef std::shared_ptr<PDBLogger> PDBLoggerPtr;
42 
43 class PDBLogger {
44 public:
45  // opens up a logger; output is written to the specified file
46  PDBLogger(std::string fName);
47 
48  // opens up the logger
49  void open(std::string fName);
50 
51  // JiaNote: why we need an empty logger here?
52  // empty logger
53  // PDBLogger();
54 
55  // closes the text file
56  ~PDBLogger();
57 
58  // added by Jia, so that we can disable debug for performance testing
59  void setEnabled(bool enabled);
60 
61  // writes a line of text to the log file
62  void writeLn(std::string writeMe);
63 
64  // write data, added by Jia
65  void write(char* data, unsigned int length);
66 
67  // write int, added by Jia
68  void writeInt(int writeMe);
69 
71 
73 
74  // Log Levels are:
75  //
76  // OFF,
77  // FATAL,
78  // ERROR,
79  // WARN,
80  // INFO,
81  // DEBUG,
82  // TRACE
83 
84  // writes a line of text to the log file, if log level FATAL, ERROR, WARN, INFO, DEBUG or TRACE
85  // is activated
86  void fatal(std::string writeMe);
87 
88  // writes a line of text to the log file, if log level ERROR, WARN, INFO, DEBUG or TRACE is
89  // activated
90  void error(std::string writeMe);
91 
92  // writes a line of text to the log file, if log level WARN, INFO, DEBUG or TRACE is activated
93  void warn(std::string writeMe);
94 
95  // writes a line of text to the log file, if log level INFO, DEBUG or TRACE is activated
96  void info(std::string writeMe);
97 
98  // writes a line of text to the log file, if log level DEBUG or TRACE is activated
99  void debug(std::string writeMe);
100 
101  // writes a line of text to the log file, if log level TRACE is activated
102  void trace(std::string writeMe);
103 
104 private:
105  // prohibits two people from writing to the file at the same time
106  pthread_mutex_t fileLock;
107 
108  // the location we are writing to
109  FILE* outputFile;
110 
111  bool enabled = true;
112 
113  LogLevel loglevel = WARN;
114 };
115 }
116 
117 #endif /* PDBLOGGER_H */
void writeInt(int writeMe)
Definition: PDBLogger.cc:96
void fatal(std::string writeMe)
Definition: PDBLogger.cc:161
void setLoglevel(LogLevel loglevel)
Definition: PDBLogger.cc:216
void writeLn(std::string writeMe)
Definition: PDBLogger.cc:170
void info(std::string writeMe)
Definition: PDBLogger.cc:135
void error(std::string writeMe)
Definition: PDBLogger.cc:153
pthread_mutex_t fileLock
Definition: PDBLogger.h:106
FILE * outputFile
Definition: PDBLogger.h:109
void write(char *data, unsigned int length)
Definition: PDBLogger.cc:199
LogLevel getLoglevel()
Definition: PDBLogger.cc:212
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
PDBLogger(std::string fName)
Definition: PDBLogger.cc:35
void debug(std::string writeMe)
Definition: PDBLogger.cc:126
void open(std::string fName)
Definition: PDBLogger.cc:57
void setEnabled(bool enabled)
Definition: PDBLogger.cc:208
void warn(std::string writeMe)
Definition: PDBLogger.cc:144
void trace(std::string writeMe)
Definition: PDBLogger.cc:117
LogLevel loglevel
Definition: PDBLogger.h:113
Definition: LogLevel.h:40
LogLevel
Definition: LogLevel.h:40