Apache log4cxx  Version 0.13.0
jsonlayout.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_JSON_LAYOUT_H
19 #define _LOG4CXX_JSON_LAYOUT_H
20 
21 #include <log4cxx/layout.h>
24 
25 #if defined(_MSC_VER)
26  #pragma warning ( push )
27  #pragma warning ( disable: 4251 )
28 #endif
29 
30 
31 namespace log4cxx
32 {
36 class LOG4CXX_EXPORT JSONLayout : public Layout
37 {
38  private:
39  // Print no location info by default
40  bool locationInfo; //= false
41  bool prettyPrint; //= false
42 
43  helpers::ISO8601DateFormat dateFormat;
44 
45  protected:
46 
49 
50  void appendQuotedEscapedString(LogString& buf, const LogString& input) const;
51  void appendSerializedMDC(LogString& buf,
52  const spi::LoggingEventPtr& event) const;
53  void appendSerializedNDC(LogString& buf,
54  const spi::LoggingEventPtr& event) const;
55  void appendSerializedLocationInfo(LogString& buf,
56  const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) const;
57 
58  public:
64 
65  JSONLayout();
66 
74  inline void setLocationInfo(bool locationInfoFlag)
75  {
76  this->locationInfo = locationInfoFlag;
77  }
78 
79 
83  inline bool getLocationInfo() const
84  {
85  return locationInfo;
86  }
87 
95  inline void setPrettyPrint(bool prettyPrintFlag)
96  {
97  this->prettyPrint = prettyPrintFlag;
98  }
99 
103  inline bool getPrettyPrint() const
104  {
105  return prettyPrint;
106  }
107 
108 
112  virtual LogString getContentType() const
113  {
114  return LOG4CXX_STR("application/json");
115  }
116 
120  virtual void activateOptions(log4cxx::helpers::Pool& /* p */) {}
121 
125  virtual void setOption(const LogString& option, const LogString& value);
126 
127  virtual void format(LogString& output,
128  const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool) const;
129 
133  virtual bool ignoresThrowable() const
134  {
135  return false;
136  }
137 
138 }; // class JSONLayout
140 } // namespace log4cxx
141 
142 #if defined(_MSC_VER)
143  #pragma warning (pop)
144 #endif
145 
146 #endif // _LOG4CXX_JSON_LAYOUT_H
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
void setPrettyPrint(bool prettyPrintFlag)
The PrettyPrint option takes a boolean value.
Definition: jsonlayout.h:95
LogString ppIndentL2
Definition: jsonlayout.h:48
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:37
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141
bool getLocationInfo() const
Returns the current value of the LocationInfo option.
Definition: jsonlayout.h:83
LogString ppIndentL1
Definition: jsonlayout.h:47
Extend this abstract class to create your own log layout format.
Definition: layout.h:37
LOG4CXX_PTR_DEF(Appender)
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
bool getPrettyPrint() const
Returns the current value of the PrettyPrint option.
Definition: jsonlayout.h:103
virtual bool ignoresThrowable() const
The JSON layout handles the throwable contained in logging events.
Definition: jsonlayout.h:133
Definition: pool.h:32
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:159
Formats a date in the format yyyy-MM-dd HH:mm:ss,SSS for example "1999-11-27 15:49:37,459".
Definition: iso8601dateformat.h:36
virtual void activateOptions(log4cxx::helpers::Pool &)
No options to activate.
Definition: jsonlayout.h:120
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66
virtual LogString getContentType() const
Returns the content type output by this layout, i.e "application/json".
Definition: jsonlayout.h:112
This layout outputs events in a JSON dictionary.
Definition: jsonlayout.h:36