Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef LOGGER_HPP
00028 #define LOGGER_HPP
00029
00030
00031 #include <cstdio>
00032 #include <cstdarg>
00033 #include <string>
00034
00035 #ifndef DOXYGEN_SHOULD_IGNORE_THIS
00036
00038
00039
00040
00041
00042
00043
00045 #ifdef WIN32
00046 #define DECLSPEC __declspec(dllexport)
00047 #else
00048 #define DECLSPEC
00049 #endif
00050
00051
00052 #ifndef CALLCONVENTION
00053 #ifdef WIN32
00054 #define CALLCONVENTION __cdecl
00055 #else
00056 #define CALLCONVENTION
00057 #endif
00058 #endif
00059
00060
00061
00062
00063 #define LOGGER_MAJOR_VERSION 0
00064 #define LOGGER_MINOR_VERSION 1
00065 #define LOGGER_PATCH_VERSION 0
00066
00068 #endif
00069
00079 struct LoggerVersion
00080 {
00081 int major;
00082 int minor;
00083 int patch;
00084 };
00085
00221 class DECLSPEC Logger
00222 {
00223 public:
00224
00230 Logger();
00231
00258 bool Init();
00259
00278 bool Init(const std::string& base_name);
00279
00310 bool Init(FILE* file_handle, const std::string& base_name);
00311
00320 ~Logger();
00321
00332 void Close();
00333
00346 inline static LoggerVersion GetCompiledVersion()
00347 {
00348 LoggerVersion ver;
00349 ver.major = LOGGER_MAJOR_VERSION;
00350 ver.minor = LOGGER_MINOR_VERSION;
00351 ver.patch = LOGGER_PATCH_VERSION;
00352 return ver;
00353 }
00354
00376 static LoggerVersion GetLinkedVersion();
00377
00387 static bool IsCompiledWithLocking();
00388
00435 int LogEvent(unsigned int priority,
00436 const char* keyword, const char* subkeyword,
00437 const char* text, ...);
00438
00446 int LogEventv(unsigned int priority,
00447 const char* keyword, const char* subkeyword,
00448 const char* text, va_list argp);
00449
00466 int LogEventNoFormat(unsigned int priority,
00467 const char* keyword, const char* subkeyword,
00468 const char* text);
00469
00475 void Enable();
00476
00481 void Disable();
00482
00490 bool IsEnabled() const;
00491
00496 void Flush();
00497
00505 void EnableAutoFlush();
00506
00514 void DisableAutoFlush();
00515
00523 bool IsAutoFlushEnabled() const;
00524
00536 void SetThresholdPriority(unsigned int thresh_val);
00537
00545 unsigned int GetThresholdPriority() const;
00546
00557 void SetDefaultPriority(unsigned int pri_level);
00558
00566 unsigned int GetDefaultPriority() const;
00567
00579 void SetMinSegmentSize(unsigned int num_bytes);
00580
00590 unsigned int GetMinSegmentSize() const;
00591
00599 void EchoOn();
00600
00606 void EchoOff();
00607
00615 bool IsEchoOn() const;
00616
00626 void SetEchoToStdout();
00627
00636 void SetEchoToStderr();
00637
00638
00639
00640
00641
00642
00643
00644
00652 void SetPreLines(unsigned int pre_lines);
00653
00661 void SetPostLines(unsigned int post_lines);
00662
00672 void SetNewLines(unsigned int pre_lines, unsigned int post_lines);
00673
00681 unsigned int GetPreLines() const;
00682
00690 unsigned int GetPostLines() const;
00691
00704 bool WillLog(unsigned int which_priority) const;
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00758 void SetSegmentMinWidth(unsigned int width);
00759
00765 unsigned int GetSegmentMinWidth() const;
00766
00767 private:
00768
00769 bool OpenFile(const std::string& filename);
00770 bool CloseFile();
00771 bool SegmentFile();
00772
00773 int PrintHeaderToFileHandle(FILE* file_handle,
00774 unsigned int pre_new_lines,
00775 unsigned int priority,
00776 const char* time_stamp,
00777 const char* keyword,
00778 const char* subkeyword);
00779
00780 int PrintFooterToFileHandle(FILE* file_handle,
00781 unsigned int post_new_lines,
00782 bool auto_flush_enabled);
00783
00784
00785 std::string baseName;
00786
00787
00788 FILE* fileHandle;
00789 FILE* echoHandle;
00791 unsigned int thresholdPriority;
00792 unsigned int defaultPriority;
00794 bool echoOn;
00795 bool loggingEnabled;
00796 bool autoFlushEnabled;
00798 unsigned int preNewLines;
00799 unsigned int postNewLines;
00801 unsigned int segmentNumber;
00802 unsigned int currentByteCount;
00803 unsigned int minSegmentBytes;
00805
00806
00807
00808 unsigned int segmentMinWidth;
00810 #ifdef LOGGER_ENABLE_LOCKING
00811
00815 mutable void* loggerMutex;
00816 #endif
00817 };
00818
00826 extern Logger g_logger;
00827
00828
00829
00830 #endif // LOGGER_HPP
00831