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 #ifndef LOG_CONFIG_H
00027 #define LOG_CONFIG_H
00028 
00029 #include "libts.h"
00030 #include "P_RecProcess.h"
00031 #include "ProxyConfig.h"
00032 
00033 
00034 
00035 
00036 enum
00037 {
00038   
00039   log_stat_event_log_error_ok_stat,
00040   log_stat_event_log_error_skip_stat,
00041   log_stat_event_log_error_aggr_stat,
00042   log_stat_event_log_error_full_stat,
00043   log_stat_event_log_error_fail_stat,
00044 
00045   log_stat_event_log_access_ok_stat,
00046   log_stat_event_log_access_skip_stat,
00047   log_stat_event_log_access_aggr_stat,
00048   log_stat_event_log_access_full_stat,
00049   log_stat_event_log_access_fail_stat,
00050 
00051   
00052   log_stat_num_sent_to_network_stat,
00053   log_stat_num_lost_before_sent_to_network_stat,
00054   log_stat_num_received_from_network_stat,
00055   log_stat_num_flush_to_disk_stat,
00056   log_stat_num_lost_before_flush_to_disk_stat,
00057 
00058   log_stat_bytes_lost_before_preproc_stat,
00059   log_stat_bytes_sent_to_network_stat,
00060   log_stat_bytes_lost_before_sent_to_network_stat,
00061   log_stat_bytes_received_from_network_stat,
00062 
00063   log_stat_bytes_flush_to_disk_stat,
00064   log_stat_bytes_lost_before_flush_to_disk_stat,
00065   log_stat_bytes_written_to_disk_stat,
00066   log_stat_bytes_lost_before_written_to_disk_stat,
00067 
00068   
00069   log_stat_log_files_open_stat,
00070   log_stat_log_files_space_used_stat,
00071 
00072   log_stat_count
00073 };
00074 
00075 extern RecRawStatBlock *log_rsb;
00076 
00077 struct dirent;
00078 struct LogCollationAccept;
00079 struct PreDefinedFormatList;
00080 struct PreDefinedFormatInfo;
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 class LogConfig : public ConfigInfo
00109 {
00110 
00111 public:
00112 
00113   LogConfig();
00114   ~LogConfig();
00115 
00116   void init(LogConfig * previous_config = 0);
00117   void display(FILE * fd = stdout);
00118   void setup_log_objects();
00119 
00120   static void register_configs();
00121   static int reconfigure(const char *name, RecDataT data_type, RecData data, void *cookie);
00122 
00123   static void register_config_callbacks();
00124   static void register_stat_callbacks();
00125   static void register_mgmt_callbacks();
00126 
00127   bool space_to_write(int64_t bytes_to_write);
00128 
00129   bool am_collation_host() const { return collation_mode == Log::COLLATION_HOST; }
00130   bool space_is_short() { return !space_to_write(max_space_mb_headroom * LOG_MEGABYTE); };
00131 
00132   void increment_space_used(int bytes) {
00133     m_space_used += bytes;
00134     m_partition_space_left -= bytes;
00135   }
00136 
00137   void update_space_used();
00138   void read_configuration_variables();
00139 
00140 
00141   static void *reconfigure_mgmt_variables(void *token, char *data_raw, int data_len);
00142 
00143   int get_max_space_mb() {
00144     return (use_orphan_log_space_value ? max_space_mb_for_orphan_logs : max_space_mb_for_logs);
00145   }
00146 
00147   void transfer_objects(LogConfig * old_config) {
00148     log_object_manager.transfer_objects(old_config->log_object_manager);
00149   }
00150 
00151   bool has_api_objects() const { return log_object_manager.has_api_objects(); }
00152 
00153 public:
00154   bool initialized;
00155   bool reconfiguration_needed;
00156   bool logging_space_exhausted;
00157   int64_t m_space_used;
00158   int64_t m_partition_space_left;
00159   bool roll_log_files_now;      
00160 
00161   LogObjectManager log_object_manager;
00162   LogFilterList global_filter_list;
00163   LogFormatList global_format_list;
00164 
00165   int log_buffer_size;
00166   int max_secs_per_buffer;
00167   int max_space_mb_for_logs;
00168   int max_space_mb_for_orphan_logs;
00169   int max_space_mb_headroom;
00170   int logfile_perm;
00171   bool squid_log_enabled;
00172   bool squid_log_is_ascii;
00173   bool common_log_enabled;
00174   bool common_log_is_ascii;
00175   bool extended_log_enabled;
00176   bool extended_log_is_ascii;
00177   bool extended2_log_enabled;
00178   bool extended2_log_is_ascii;
00179   bool separate_icp_logs;
00180   bool separate_host_logs;
00181   int collation_mode;
00182   int collation_port;
00183   bool collation_host_tagged;
00184   int collation_preproc_threads;
00185   int collation_retry_sec;
00186   int collation_max_send_buffers;
00187   Log::RollingEnabledValues rolling_enabled;
00188   int rolling_interval_sec;
00189   int rolling_offset_hr;
00190   int rolling_size_mb;
00191   bool auto_delete_rolled_files;
00192   bool custom_logs_enabled;
00193 
00194   bool search_log_enabled;
00195   int search_rolling_interval_sec;
00196   unsigned int search_server_ip_addr;
00197   int search_server_port;
00198   int search_top_sites;
00199   char *search_log_filters;
00200   char *search_url_filter;
00201   char *search_log_file_one;
00202   char *search_log_file_two;
00203 
00204   int sampling_frequency;
00205   int file_stat_frequency;
00206   int space_used_frequency;
00207 
00208   int ascii_buffer_size;
00209   int max_line_size;
00210 
00211   char *hostname;
00212   char *logfile_dir;
00213   char *squid_log_name;
00214   char *squid_log_header;
00215   char *common_log_name;
00216   char *common_log_header;
00217   char *extended_log_name;
00218   char *extended_log_header;
00219   char *extended2_log_name;
00220   char *extended2_log_header;
00221   char *collation_host;
00222   char *collation_secret;
00223   char *xml_config_file;
00224   char *hosts_config_file;
00225 
00226 private:
00227 
00228   void read_xml_log_config(int from_memory);
00229   char **read_log_hosts_file(size_t * nhosts);
00230 
00231   void setup_default_values();
00232   void setup_collation(LogConfig * prev_config);
00233   LogFilter *split_by_protocol(const PreDefinedFormatList & pre_def_info_list);
00234   size_t split_by_hostname(const PreDefinedFormatList & pre_def_info_list, LogFilter * reject_protocol);
00235   LogObject * create_predefined_object(const PreDefinedFormatInfo * pdi, size_t nfilters,
00236         LogFilter ** filters, const char *filt_name = 0, bool force_extension = false);
00237   void create_predefined_objects_with_filter(const PreDefinedFormatList &pre_def_info_list, size_t nfilters,
00238         LogFilter ** filters, const char *filt_name = 0, bool force_extension = false);
00239 
00240   void add_filters_to_search_log_object(const char *format_name);
00241 
00242 private:
00243   
00244   
00245   
00246   bool use_orphan_log_space_value;
00247 
00248   LogCollationAccept *m_log_collation_accept;
00249 
00250   struct dirent *m_dir_entry;
00251   char *m_pDir;
00252   bool m_disk_full;
00253   bool m_disk_low;
00254   bool m_partition_full;
00255   bool m_partition_low;
00256   bool m_log_directory_inaccessible;
00257 
00258 private:
00259   
00260   LogConfig(const LogConfig &);
00261   LogConfig & operator=(const LogConfig &);
00262 };
00263 
00264 
00265 
00266 
00267 
00268 struct LogDeleteCandidate
00269 {
00270   time_t mtime;
00271   char *name;
00272   int64_t size;
00273 };
00274 
00275 #endif