• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

LogFormat.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
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   // We start the numbering at 4 to compatibility with Traffic Server 4.x, which used
00036   // to have the predefined log formats enumerated above ...
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, // ie. ASCII pipe
00046   N_LOGFILE_TYPES
00047 };
00048 
00049 /*-------------------------------------------------------------------------
00050   LogFormat
00051 
00052   Now, this object will simply store the characteristics of a log format,
00053   which is defined as a set of fields.
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   // these are static because m_tagging_on is a class variable
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;     // flag to control tagging, class
00104   // variable
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   // -- member functions that are not allowed --
00121   LogFormat();
00122   LogFormat & operator=(LogFormat & rhs);
00123 };
00124 
00125 // For text logs, there is no format string; we'll simply log the
00126 // entire entry as a string without any field substitutions.  To
00127 // indicate this, the format_str will be NULL.
00128 static inline LogFormat *
00129 MakeTextLogFormat(const char * name = "text")
00130 {
00131   return new LogFormat(name, NULL /* format_str */);
00132 }
00133 
00134 /*-------------------------------------------------------------------------
00135   LogFormatList
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   // -- member functions that are not allowed --
00157   LogFormatList(const LogFormatList & rhs);
00158   LogFormatList & operator=(const LogFormatList & rhs);
00159 };
00160 
00161 #endif

Generated by  doxygen 1.7.1