|
Apache Log4cxx
Version 2.0.0
|
This layout outputs each event as a single line JSON object using the field names of the Elastic Common Schema (ECS), as described in the ECS logging specification. More...
#include <ecslayout.h>
Public Member Functions | |
| ECSLayout () | |
| ~ECSLayout () | |
| void | setServiceName (const LogString &newValue) |
Use newValue as the service.name field value. | |
| const LogString & | getServiceName () const |
| The service.name field value. | |
| void | setServiceVersion (const LogString &newValue) |
Use newValue as the service.version field value. | |
| const LogString & | getServiceVersion () const |
| The service.version field value. | |
| void | setServiceEnvironment (const LogString &newValue) |
Use newValue as the service.environment field value, e.g. | |
| const LogString & | getServiceEnvironment () const |
| The service.environment field value. | |
| void | setServiceNodeName (const LogString &newValue) |
Use newValue as the service.node.name field value, which identifies a particular instance of a service. | |
| const LogString & | getServiceNodeName () const |
| The service.node.name field value. | |
| void | setEventDataset (const LogString &newValue) |
Use newValue as the event.dataset field value. | |
| const LogString & | getEventDataset () const |
| The event.dataset field value (the ServiceName option value when EventDataset is empty). | |
| void | setLocationInfo (bool newValue) |
| Include the source code location (the log.origin. | |
| bool | getLocationInfo () const |
| Is the source code location of the logging request included? | |
| LogString | getContentType () const override |
| Returns the content type output by this layout, i.e "application/json". | |
| bool | activateOptions () override |
| Activate the options that were previously set with calls to option setters. | |
| void | setOption (const LogString &option, const LogString &value) override |
Override this method to set option to value. | |
| void | format (LogString &output, const spi::LoggingEventPtr &event) const override |
Append the attributes of event as a single line JSON object onto output. | |
| bool | ignoresThrowable () const override |
| The ECS layout handles the throwable contained in logging events. | |
| void | format (LogString &output, const spi::LoggingEventPtr &event, helpers::Pool &p) const |
| Public Member Functions inherited from log4cxx::Layout | |
| virtual | ~Layout () |
| void | format (LogString &output, const spi::LoggingEventPtr &event, helpers::Pool &p) const |
| virtual void | appendHeader (LogString &output) |
| Append the header for the layout format. | |
| void | appendHeader (LogString &output, helpers::Pool &p) |
| virtual void | appendFooter (LogString &output) |
| Append the footer for the layout format. | |
| void | appendFooter (LogString &output, helpers::Pool &p) |
| bool | activateOptions () override |
| Activate the options that were previously set with calls to option setters. | |
| void | activateOptions (helpers::Pool &) |
| Public Member Functions inherited from log4cxx::spi::OptionHandler | |
| virtual | ~OptionHandler () |
| void | activateOptions (helpers::Pool &) |
| Public Member Functions inherited from log4cxx::helpers::Object | |
| virtual | ~Object () |
| virtual const helpers::Class & | getClass () const =0 |
| virtual bool | instanceof (const Class &clazz) const =0 |
| virtual const void * | cast (const Class &clazz) const =0 |
Additional Inherited Members | |
| Protected Member Functions inherited from log4cxx::Layout | |
| size_t | getFormattedEventCharacterCount () const |
| The expected length of a formatted event excluding the message text. | |
This layout outputs each event as a single line JSON object using the field names of the Elastic Common Schema (ECS), as described in the ECS logging specification.
The output can be sent to Elasticsearch (for example, using Filebeat, Logstash or fluent-bit) without further parsing.
The fields in each line are:
| Field | Content | Included |
|---|---|---|
| @timestamp | The event time in UTC with millisecond precision, e.g. 2026-11-15T10:20:30.123Z | always |
| log.level | The event level, e.g. INFO | always |
| message | The rendered message | always |
| ecs.version | 1.2.0 | always |
| log.logger | The logger name | always |
| process.thread.name | The name of the thread that made the logging request (or its identifier when the name is not available) | always |
| service.name | The ServiceName option value | when not empty |
| service.version | The ServiceVersion option value | when not empty |
| service.environment | The ServiceEnvironment option value | when not empty |
| service.node.name | The ServiceNodeName option value | when not empty |
| event.dataset | The EventDataset option value, or the ServiceName option value | when not empty |
| tags | An array containing the nested diagnostic context (NDC) | when the NDC is not empty |
| key | The value of each mapped diagnostic context (MDC) entry | when the MDC is not empty |
| log.origin.file.name | The source file name of the logging request | when the LocationInfo option is true and location information is available |
| log.origin.file.line | The source line number (a JSON number) | as above |
| log.origin.function | The qualified function name, e.g. com::foo::Bar::doIt | as above |
Each mapped diagnostic context (MDC) entry is added using its key as the field name, so an MDC key such as trace.id or user.id populates the ECS field of that name. An MDC entry that has the same name as a field already added by this layout is not output, so the JSON object never contains a duplicate field name.
Here is an example configuration that writes ECS JSON lines to a file:
A logging request in this configuration produces a line like:
To send the events to a log server instead, use this layout in a JSONSocketAppender.
| log4cxx::ECSLayout::ECSLayout | ( | ) |
| log4cxx::ECSLayout::~ECSLayout | ( | ) |
|
overridevirtual |
Activate the options that were previously set with calls to option setters.
Calculates the length of the formatted output.
Implements log4cxx::spi::OptionHandler.
|
overridevirtual |
Append the attributes of event as a single line JSON object onto output.
Implements log4cxx::Layout.
| void log4cxx::Layout::format | ( | LogString & | output, |
| const spi::LoggingEventPtr & | event, | ||
| helpers::Pool & | p ) const |
|
overridevirtual |
Returns the content type output by this layout, i.e "application/json".
Reimplemented from log4cxx::Layout.
| const LogString & log4cxx::ECSLayout::getEventDataset | ( | ) | const |
The event.dataset field value (the ServiceName option value when EventDataset is empty).
| bool log4cxx::ECSLayout::getLocationInfo | ( | ) | const |
Is the source code location of the logging request included?
| const LogString & log4cxx::ECSLayout::getServiceEnvironment | ( | ) | const |
The service.environment field value.
| const LogString & log4cxx::ECSLayout::getServiceName | ( | ) | const |
The service.name field value.
| const LogString & log4cxx::ECSLayout::getServiceNodeName | ( | ) | const |
The service.node.name field value.
| const LogString & log4cxx::ECSLayout::getServiceVersion | ( | ) | const |
The service.version field value.
|
inlineoverridevirtual |
The ECS layout handles the throwable contained in logging events.
Hence, this method returns false.
Implements log4cxx::Layout.
| void log4cxx::ECSLayout::setEventDataset | ( | const LogString & | newValue | ) |
Use newValue as the event.dataset field value.
When empty (the default), the ServiceName option value is used.
| void log4cxx::ECSLayout::setLocationInfo | ( | bool | newValue | ) |
Include the source code location (the log.origin.
* fields) of the logging request when newValue is true. By default, location information is not included.
|
overridevirtual |
Override this method to set option to value.
| Supported options | Supported values | Default value |
|---|---|---|
| ServiceName | {any} | - |
| ServiceVersion | {any} | - |
| ServiceEnvironment | {any} | - |
| ServiceNodeName | {any} | - |
| EventDataset | {any} | (the ServiceName value) |
| LocationInfo | True,False | false |
Reimplemented from log4cxx::spi::OptionHandler.
| void log4cxx::ECSLayout::setServiceEnvironment | ( | const LogString & | newValue | ) |
Use newValue as the service.environment field value, e.g.
production or staging. An empty value (the default) omits the field.
| void log4cxx::ECSLayout::setServiceName | ( | const LogString & | newValue | ) |
Use newValue as the service.name field value.
An empty value (the default) omits the field.
| void log4cxx::ECSLayout::setServiceNodeName | ( | const LogString & | newValue | ) |
Use newValue as the service.node.name field value, which identifies a particular instance of a service.
An empty value (the default) omits the field.
| void log4cxx::ECSLayout::setServiceVersion | ( | const LogString & | newValue | ) |
Use newValue as the service.version field value.
An empty value (the default) omits the field.