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 #ifndef LOG_FORMAT_H
00025 #define LOG_FORMAT_H
00026
00027 #define LOG_FIELD_MARKER '\377'
00028
00029 #include "libts.h"
00030 #include "LogField.h"
00031 #include "InkXml.h"
00032
00033 enum LogFormatType
00034 {
00035
00036
00037 LOG_FORMAT_CUSTOM = 4,
00038 LOG_FORMAT_TEXT = 5
00039 };
00040
00041 enum LogFileFormat
00042 {
00043 LOG_FILE_BINARY,
00044 LOG_FILE_ASCII,
00045 LOG_FILE_PIPE,
00046 N_LOGFILE_TYPES
00047 };
00048
00049
00050
00051
00052
00053
00054
00055
00056 class LogFormat
00057 {
00058 public:
00059 LogFormat(const char *name, const char *format_str, unsigned interval_sec = 0);
00060 LogFormat(const char *name, const char *fieldlist_str, const char *printf_str, unsigned interval_sec = 0);
00061 LogFormat(const LogFormat & rhs);
00062
00063 ~LogFormat();
00064
00065 void display(FILE * fd = stdout);
00066 void displayAsXML(FILE * fd = stdout);
00067
00068 bool valid() const { return m_valid; }
00069 char *name() const { return m_name_str; }
00070 char *fieldlist() const { return m_fieldlist_str; }
00071 char *format_string() const { return m_format_str; }
00072 int32_t name_id() const { return m_name_id; }
00073 unsigned fieldlist_id() const { return m_fieldlist_id; }
00074 LogFormatType type() const { return m_format_type; }
00075 char *printf_str() const { return m_printf_str; }
00076 bool is_aggregate() const { return m_aggregate; }
00077 unsigned field_count() const { return m_field_count; }
00078 long interval() const { return m_interval_sec; }
00079
00080 public:
00081 static int32_t id_from_name(const char *name);
00082 static LogFormat *format_from_specification(char *spec,
00083 char **file_name, char **file_header, LogFileFormat * file_type);
00084 static int parse_symbol_string(const char *symbol_string, LogFieldList *field_list, bool *contains_aggregates);
00085 static int parse_format_string(const char *format_str, char **printf_str, char **fields_str);
00086 static int parse_escape_string(const char *str, int len);
00087
00088
00089 static void turn_tagging_on() { m_tagging_on = true; }
00090 static void turn_tagging_off() { m_tagging_on = false; }
00091
00092 private:
00093 bool setup(const char *name, const char *format_str, unsigned interval_sec = 0);
00094 void init_variables(const char *name, const char *fieldlist_str, const char *printf_str, unsigned interval_sec);
00095
00096 public:
00097 LogFieldList m_field_list;
00098 long m_interval_sec;
00099 long m_interval_next;
00100 char *m_agg_marshal_space;
00101
00102 private:
00103 static bool m_tagging_on;
00104
00105 bool m_valid;
00106 char *m_name_str;
00107 int32_t m_name_id;
00108 char *m_fieldlist_str;
00109 unsigned m_fieldlist_id;
00110 unsigned m_field_count;
00111 char *m_printf_str;
00112 bool m_aggregate;
00113 char *m_format_str;
00114 LogFormatType m_format_type;
00115
00116 public:
00117 LINK(LogFormat, link);
00118
00119 private:
00120
00121 LogFormat();
00122 LogFormat & operator=(LogFormat & rhs);
00123 };
00124
00125
00126
00127
00128 static inline LogFormat *
00129 MakeTextLogFormat(const char * name = "text")
00130 {
00131 return new LogFormat(name, NULL );
00132 }
00133
00134
00135
00136
00137
00138 class LogFormatList
00139 {
00140 public:
00141 LogFormatList();
00142 ~LogFormatList();
00143
00144 void add(LogFormat * format, bool copy = true);
00145 LogFormat *find_by_name(const char *name) const;
00146
00147 LogFormat *first() const { return m_format_list.head; }
00148 LogFormat *next(LogFormat * here) const { return (here->link).next; }
00149
00150 void clear();
00151 unsigned count();
00152 void display(FILE * fd = stdout);
00153 private:
00154 Queue<LogFormat> m_format_list;
00155
00156
00157 LogFormatList(const LogFormatList & rhs);
00158 LogFormatList & operator=(const LogFormatList & rhs);
00159 };
00160
00161 #endif