~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/logging/LogFormat.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
 
 
25
 
 
26
#ifndef LOG_FORMAT_H
 
27
#define LOG_FORMAT_H
 
28
 
 
29
#define LOG_FIELD_MARKER        '\377'
 
30
 
 
31
#include "libts.h"
 
32
#include "LogField.h"
 
33
#include "LogFormatType.h"
 
34
#include "InkXml.h"
 
35
 
 
36
/*-------------------------------------------------------------------------
 
37
  LogFormat
 
38
 
 
39
  Ok, as of 3.1, the role of the LogFormat object changes greatly.  Before
 
40
  it was the central object in the logging system that defined each "file"
 
41
  that would be created, and all other objects hung off of it.
 
42
 
 
43
  Now, this object will simply store the characteristics of a log format,
 
44
  which is defined as a set of fields.
 
45
  -------------------------------------------------------------------------*/
 
46
 
 
47
class LogFormat
 
48
{
 
49
public:
 
50
  LogFormat(LogFormatType type);
 
51
  LogFormat(const char *name, const char *format_str, unsigned interval_sec = 0);
 
52
  LogFormat(const char *name, const char *fieldlist_str, const char *printf_str, unsigned interval_sec = 0);
 
53
  LogFormat(const LogFormat & rhs);
 
54
  ~LogFormat();
 
55
 
 
56
  void display(FILE * fd = stdout);
 
57
  void displayAsXML(FILE * fd = stdout);
 
58
 
 
59
  bool valid()
 
60
  {
 
61
    return m_valid;
 
62
  }
 
63
  char *name()
 
64
  {
 
65
    return m_name_str;
 
66
  }
 
67
  char *fieldlist()
 
68
  {
 
69
    return m_fieldlist_str;
 
70
  }
 
71
  char *format_string()
 
72
  {
 
73
    return m_format_str;
 
74
  };
 
75
  int32_t name_id()
 
76
  {
 
77
    return m_name_id;
 
78
  }
 
79
  unsigned fieldlist_id()
 
80
  {
 
81
    return m_fieldlist_id;
 
82
  }
 
83
  LogFormatType type()
 
84
  {
 
85
    return m_format_type;
 
86
  }
 
87
  char *printf_str()
 
88
  {
 
89
    return m_printf_str;
 
90
  }
 
91
  bool is_aggregate()
 
92
  {
 
93
    return m_aggregate;
 
94
  }
 
95
  unsigned field_count()
 
96
  {
 
97
    return m_field_count;
 
98
  }
 
99
  long interval()
 
100
  {
 
101
    return m_interval_sec;
 
102
  };
 
103
 
 
104
public:
 
105
  static int32_t id_from_name(const char *name);
 
106
  static LogFormat *format_from_specification(char *spec,
 
107
                                              char **file_name, char **file_header, LogFileFormat * file_type);
 
108
  static int parse_symbol_string(const char *symbol_string, LogFieldList *field_list, bool *contains_aggregates);
 
109
  static int parse_format_string(const char *format_str, char **printf_str, char **fields_str);
 
110
 
 
111
  // these are static because m_tagging_on is a class variable
 
112
  //
 
113
  static void turn_tagging_on()
 
114
  {
 
115
    m_tagging_on = true;
 
116
  };
 
117
  static void turn_tagging_off()
 
118
  {
 
119
    m_tagging_on = false;
 
120
  };
 
121
 
 
122
private:
 
123
  void setup(const char *name, const char *format_str, unsigned interval_sec = 0);
 
124
  void init_variables(const char *name, const char *fieldlist_str, const char *printf_str, unsigned interval_sec);
 
125
 
 
126
public:
 
127
  LogFieldList m_field_list;
 
128
  long m_interval_sec;
 
129
  long m_interval_next;
 
130
  char *m_agg_marshal_space;
 
131
 
 
132
  static const char *const squid_format;        // pre defined formats
 
133
  static const char *const common_format;
 
134
  static const char *const extended_format;
 
135
  static const char *const extended2_format;
 
136
 
 
137
private:
 
138
  static bool m_tagging_on;     // flag to control tagging, class
 
139
  // variable
 
140
  bool m_valid;
 
141
  char *m_name_str;
 
142
  int32_t m_name_id;
 
143
  char *m_fieldlist_str;
 
144
  unsigned m_fieldlist_id;
 
145
  unsigned m_field_count;
 
146
  char *m_printf_str;
 
147
  bool m_aggregate;
 
148
  char *m_format_str;
 
149
  LogFormatType m_format_type;
 
150
 
 
151
public:
 
152
  LINK(LogFormat, link);
 
153
 
 
154
private:
 
155
  // -- member functions that are not allowed --
 
156
  LogFormat();
 
157
  LogFormat & operator=(LogFormat & rhs);
 
158
};
 
159
 
 
160
/*-------------------------------------------------------------------------
 
161
  LogFormatList
 
162
  -------------------------------------------------------------------------*/
 
163
 
 
164
class LogFormatList
 
165
{
 
166
public:
 
167
  LogFormatList();
 
168
  ~LogFormatList();
 
169
 
 
170
  void add(LogFormat * format, bool copy = true);
 
171
  LogFormat *find_by_name(const char *name) const;
 
172
  LogFormat *find_by_type(LogFormatType type, int32_t id) const;
 
173
 
 
174
  LogFormat *first() const
 
175
  {
 
176
    return m_format_list.head;
 
177
  }
 
178
  LogFormat *next(LogFormat * here) const
 
179
  {
 
180
    return (here->link).next;
 
181
  }
 
182
  void clear();
 
183
  unsigned count();
 
184
  void display(FILE * fd = stdout);
 
185
private:
 
186
  Queue<LogFormat> m_format_list;
 
187
 
 
188
  // -- member functions that are not allowed --
 
189
  LogFormatList(const LogFormatList & rhs);
 
190
  LogFormatList & operator=(const LogFormatList & rhs);
 
191
};
 
192
 
 
193
#endif