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 #ifndef _dgMultifileLog_h_
00027 #define _dgMultifileLog_h_
00028
00035 #include <iostream>
00036 #include <fstream>
00037 #include <string>
00038
00039 #include "dgFunnel.h"
00040
00041 namespace DGD {
00042
00063 class multifile_log: public funnel {
00064 public:
00076 class Split_criteria {
00077 public:
00078 virtual bool operator () ( unsigned long volume,
00079 unsigned long line,
00080 unsigned long column,
00081 unsigned long bytes ) const = 0;
00082 };
00083
00088 class Dont_split: public Split_criteria {
00089 public:
00090 bool operator () ( unsigned long volume,
00091 unsigned long line,
00092 unsigned long column,
00093 unsigned long bytes ) const { return false; };
00094 };
00095
00101 class Split_by_size: public Split_criteria {
00102 public:
00103 Split_by_size() : m_vol_size(1024*1024*5) {}
00104 Split_by_size( unsigned long vol_size ) : m_vol_size(vol_size) {}
00105
00106 bool operator () ( unsigned long volume,
00107 unsigned long line,
00108 unsigned long column,
00109 unsigned long bytes ) const {
00110 return ( bytes >= volume * m_vol_size );
00111 }
00112 private:
00113 unsigned long m_vol_size;
00114 };
00115
00121 class Split_by_lines: public Split_criteria {
00122 public:
00123 Split_by_lines() : m_vol_size(60000) {}
00124 Split_by_lines( unsigned long vol_size ) : m_vol_size(vol_size) {}
00125 Split_by_lines( const Split_by_lines& peer ) :
00126 m_vol_size( peer.m_vol_size ) {}
00127
00128 bool operator () ( unsigned long volume,
00129 unsigned long line,
00130 unsigned long column,
00131 unsigned long bytes ) const {
00132 return ( line >= volume * m_vol_size );
00133 }
00134 private:
00135 unsigned long m_vol_size;
00136 };
00137
00138 public:
00139 static Dont_split dont_split;
00140 static Split_by_size split_by_size;
00141 static Split_by_lines split_by_lines;
00142
00143 public:
00144 multifile_log( const char* name,
00145 Split_criteria* criteria = &split_by_size );
00146 ~multifile_log();
00147
00148 private:
00149 void operator () ( unsigned long line,
00150 unsigned long column,
00151 unsigned long bytes );
00152 std::string real_name() const;
00153
00154 private:
00155 std::ofstream m_file;
00156 std::string m_name;
00157 unsigned int m_part_count;
00158 Split_criteria* m_split;
00159 };
00160
00161
00162 };
00163
00164 #endif
00165
00166
00167
00168
00169
00170
00171
00172