Coverage Report

Created: 2026-12-01 07:12

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
  : public spi::OptionHandler
33
{
34
  public:
35
    DECLARE_ABSTRACT_LOG4CXX_OBJECT(Layout)
36
130k
    BEGIN_LOG4CXX_CAST_MAP()
37
130k
    LOG4CXX_CAST_ENTRY(Layout)
38
102k
    LOG4CXX_CAST_ENTRY(spi::OptionHandler)
39
7.34k
    END_LOG4CXX_CAST_MAP()
40
41
    virtual ~Layout();
42
43
    /**
44
    Implement this method to create your own layout format.
45
    */
46
    virtual void format(LogString& output, const spi::LoggingEventPtr& event) const = 0;
47
    /**
48
    @deprecated Backward compatability support will be removed in a future version.
49
    */
50
    [[deprecated("Use format() without a Pool parameter instead")]]
51
    void format(LogString& output, const spi::LoggingEventPtr& event, helpers::Pool& p) const;
52
53
    /**
54
    Returns the content type output by this layout. The base class
55
    returns "text/plain".
56
    */
57
    virtual LogString getContentType() const;
58
59
    /**
60
    Append the header for the layout format. The base class does
61
    nothing.
62
    */
63
    virtual void appendHeader(LogString& output);
64
    /**
65
    @deprecated Backward compatability support will be removed in a future version.
66
    */
67
    [[deprecated("Use appendHeader() without a Pool parameter instead")]]
68
    void appendHeader(LogString& output, helpers::Pool& p);
69
70
    /**
71
    Append the footer for the layout format. The base class does
72
    nothing.
73
    */
74
    virtual void appendFooter(LogString& output);
75
    /**
76
    @deprecated Backward compatability support will be removed in a future version.
77
    */
78
    [[deprecated("Use appendFooter() without a Pool parameter instead")]]
79
    void appendFooter(LogString& output, helpers::Pool& p);
80
81
    /**
82
    If the layout handles the throwable object contained within
83
    {@link spi::LoggingEvent LoggingEvent}, then the layout should return
84
    <code>false</code>. Otherwise, if the layout ignores throwable
85
    object, then the layout should return <code>true</code>.
86
87
    <p>The SimpleLayout, FMTLayout and PatternLayout return <code>true</code>.
88
    The other layouts return <code>false</code>.
89
    */
90
    virtual bool ignoresThrowable() const = 0;
91
92
    using spi::OptionHandler::activateOptions;
93
    /**
94
    \copybrief spi::OptionHandler::activateOptions()
95
96
    No action is performed in this implementation.
97
    */
98
    bool activateOptions() override;
99
  protected:
100
    /**
101
     * The expected length of a formatted event excluding the message text
102
     */
103
    size_t getFormattedEventCharacterCount() const;
104
};
105
LOG4CXX_PTR_DEF(Layout);
106
}
107
108
#endif // _LOG4CXX_LAYOUT_H