RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* file_output.h -*- C++ -*- 00002 Jeremy Barnes, 29 May 2011 00003 Copyright (c) 2011 Datacratic. All rights reserved. 00004 00005 Get the output from the given file. 00006 */ 00007 00008 #ifndef __logger__file_output_h__ 00009 #define __logger__file_output_h__ 00010 00011 #include "logger.h" 00012 #include "rotating_output.h" 00013 #include "compressing_output.h" 00014 #include "soa/service/s3.h" 00015 00016 00017 namespace Datacratic { 00018 00019 00020 /*****************************************************************************/ 00021 /* FILE OUTPUT */ 00022 /*****************************************************************************/ 00023 00031 struct NamedOutput : public CompressingOutput { 00032 00033 NamedOutput(size_t ringBufferSize = 65536); 00034 00035 virtual ~NamedOutput(); 00036 00037 virtual void open(const std::string & filename, 00038 const std::string & compression = "", 00039 int level = -1); 00040 00047 void rotate(const std::string & newFilename, 00048 const std::string & newCompression = "", 00049 int newLevel = -1); 00050 00051 virtual void close(); 00052 00053 boost::function<void (std::string)> onPreFileOpen; 00054 boost::function<void (std::string)> onPostFileOpen; 00055 boost::function<void (std::string)> onPreFileClose; 00056 boost::function<void (std::string)> onPostFileClose; 00057 00058 protected: 00059 00060 virtual std::shared_ptr<Sink> 00061 createSink(const std::string & filename, bool append) = 0; 00062 00063 void switchFile(const std::string & filename, 00064 const std::string & compression, 00065 int level); 00066 00067 void closeFile(); 00068 }; 00069 00070 00071 /*****************************************************************************/ 00072 /* FILE SINK */ 00073 /*****************************************************************************/ 00074 00077 struct FileSink : public CompressingOutput::Sink { 00078 FileSink(const std::string & filename = "", 00079 bool append = true, 00080 bool disambiguate = true); 00081 00082 virtual ~FileSink(); 00083 00084 void open(const std::string & filename, 00085 bool append, 00086 bool disambiguate); 00087 00088 virtual void close(); 00089 00090 virtual size_t write(const char * data, size_t size); 00091 00092 virtual size_t flush(FileFlushLevel flushLevel); 00093 00095 std::string currentFilename; 00096 00098 int fd; 00099 }; 00100 00101 00102 /*****************************************************************************/ 00103 /* FILE OUTPUT */ 00104 /*****************************************************************************/ 00105 00113 struct FileOutput : public NamedOutput { 00114 00115 FileOutput(const std::string & filename = "", 00116 size_t ringBufferSize = 65536); 00117 00118 virtual ~FileOutput(); 00119 00120 virtual std::shared_ptr<Sink> 00121 createSink(const std::string & filename, bool append); 00122 }; 00123 00124 00125 /*****************************************************************************/ 00126 /* ROTATING FILE OUTPUT */ 00127 /*****************************************************************************/ 00128 00131 struct RotatingFileOutput : public RotatingOutputAdaptor { 00132 00133 RotatingFileOutput(); 00134 00135 virtual ~RotatingFileOutput(); 00136 00138 void open(const std::string & filenamePattern, 00139 const std::string & periodPattern, 00140 const std::string & compression = "", 00141 int level = -1); 00142 00143 private: 00144 FileOutput * createFile(const std::string & filename); 00145 00146 std::string compression; 00147 int level; 00148 }; 00149 00150 } // namespace Datacratic 00151 00152 00153 #endif /* __logger__file_output_h__ */