Coverage Report

Created: 2026-05-30 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/include/log4cxx/layout.h
Line
Count
Source
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_LAYOUT_H
19
#define _LOG4CXX_LAYOUT_H
20
21
#include <log4cxx/helpers/object.h>
22
#include <log4cxx/spi/optionhandler.h>
23
#include <log4cxx/spi/loggingevent.h>
24
25
26
namespace LOG4CXX_NS
27
{
28
/**
29
Extend this abstract class to create your own log layout format.
30
*/
31
class LOG4CXX_EXPORT Layout
32
#if LOG4CXX_ABI_VERSION <= 15
33
  : public virtual spi::OptionHandler
34
  , public virtual helpers::Object
35
#else
36
  : public spi::OptionHandler
37
#endif
38
{
39
  public:
40
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(Layout)
41
0
    BEGIN_LOG4CXX_CAST_MAP()
42
0
    LOG4CXX_CAST_ENTRY(Layout)
43
0
    LOG4CXX_CAST_ENTRY(spi::OptionHandler)
44
0
    END_LOG4CXX_CAST_MAP()
45
46
    virtual ~Layout();
47
48
    /**
49
    Implement this method to create your own layout format.
50
    */
51
#if LOG4CXX_ABI_VERSION <= 15
52
    void format(LogString& output, const spi::LoggingEventPtr& event) const;
53
    /**
54
    @deprecated The \c pool parameter is not used and will be removed in a future version.
55
    Implement this method for now, but plan to migrate to format() without a helpers::Pool parameter.
56
    */
57
    virtual void format(LogString& output,
58
      const spi::LoggingEventPtr& event, LOG4CXX_NS::helpers::Pool& pool) const = 0;
59
#define LOG4CXX_FORMAT_LAYOUT_FORMAL_PARAMETERS LogString& output, const spi::LoggingEventPtr& event, helpers::Pool& p
60
#else
61
    virtual void format(LogString& output, const spi::LoggingEventPtr& event) const = 0;
62
#define LOG4CXX_FORMAT_LAYOUT_FORMAL_PARAMETERS LogString& output, const spi::LoggingEventPtr& event
63
    /**
64
    @deprecated The \c pool parameter is not used and will be removed in a future version.
65
    */
66
    [[deprecated("Use format() without a Pool parameter instead")]]
67
    void format(LogString& output, const spi::LoggingEventPtr& event, helpers::Pool& p) const;
68
#endif
69
70
    /**
71
    Returns the content type output by this layout. The base class
72
    returns "text/plain".
73
    */
74
    virtual LogString getContentType() const;
75
76
    /**
77
    Append the header for the layout format. The base class does
78
    nothing.
79
    */
80
#if LOG4CXX_ABI_VERSION <= 15
81
    void appendHeader(LogString& output);
82
    /**
83
    @deprecated The \c pool parameter is not used and will be removed in a future version.
84
    Implement this method for now, but plan to migrate to appendHeader() without a helpers::Pool parameter.
85
    */
86
    virtual void appendHeader(LogString& output, LOG4CXX_NS::helpers::Pool& p);
87
#define LOG4CXX_APPEND_HEADER_FORMAL_PARAMETERS LogString& output, LOG4CXX_NS::helpers::Pool& p
88
#else
89
    virtual void appendHeader(LogString& output);
90
#define LOG4CXX_APPEND_HEADER_FORMAL_PARAMETERS LogString& output
91
    /**
92
    @deprecated The \c pool parameter is not used and will be removed in a future version.
93
    */
94
    [[deprecated("Use appendHeader() without a Pool parameter instead")]]
95
    void appendHeader(LogString& output, helpers::Pool& p);
96
#endif
97
98
    /**
99
    Append the footer for the layout format. The base class does
100
    nothing.
101
    */
102
#if LOG4CXX_ABI_VERSION <= 15
103
    void appendFooter(LogString& output);
104
    /**
105
    @deprecated The \c pool parameter is not used and will be removed in a future version.
106
    Implement this method for now, but plan to migrate to appendFooter() without a helpers::Pool parameter.
107
    */
108
    virtual void appendFooter(LogString& output, LOG4CXX_NS::helpers::Pool& p);
109
#define LOG4CXX_APPEND_FOOTER_FORMAL_PARAMETERS LogString& output, LOG4CXX_NS::helpers::Pool& p
110
#else
111
    virtual void appendFooter(LogString& output);
112
#define LOG4CXX_APPEND_FOOTER_FORMAL_PARAMETERS LogString& output
113
    /**
114
    @deprecated The \c pool parameter is not used and will be removed in a future version.
115
    */
116
    [[deprecated("Use appendFooter() without a Pool parameter instead")]]
117
    void appendFooter(LogString& output, helpers::Pool& p);
118
#endif
119
120
    /**
121
    If the layout handles the throwable object contained within
122
    {@link spi::LoggingEvent LoggingEvent}, then the layout should return
123
    <code>false</code>. Otherwise, if the layout ignores throwable
124
    object, then the layout should return <code>true</code>.
125
126
    <p>The SimpleLayout, FMTLayout and PatternLayout return <code>true</code>.
127
    The other layouts return <code>false</code>.
128
    */
129
    virtual bool ignoresThrowable() const = 0;
130
131
#if 15 < LOG4CXX_ABI_VERSION
132
    using spi::OptionHandler::activateOptions;
133
    /**
134
    \copybrief spi::OptionHandler::activateOptions()
135
136
    No action is performed in this implementation.
137
    */
138
    void activateOptions( LOG4CXX_ACTIVATE_OPTIONS_FORMAL_PARAMETERS ) override;
139
#endif
140
  protected:
141
    /**
142
     * The expected length of a formatted event excluding the message text
143
     */
144
    size_t getFormattedEventCharacterCount() const;
145
};
146
LOG4CXX_PTR_DEF(Layout);
147
}
148
149
#endif // _LOG4CXX_LAYOUT_H