/src/dcmtk/oflog/libsrc/layout.cc
Line | Count | Source |
1 | | // Module: Log4CPLUS |
2 | | // File: layout.cxx |
3 | | // Created: 6/2001 |
4 | | // Author: Tad E. Smith |
5 | | // |
6 | | // |
7 | | // Copyright 2001-2010 Tad E. Smith |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | // you may not use this file except in compliance with the License. |
11 | | // You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software |
16 | | // distributed under the License is distributed on an "AS IS" BASIS, |
17 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | // See the License for the specific language governing permissions and |
19 | | // limitations under the License. |
20 | | |
21 | | #include "dcmtk/oflog/layout.h" |
22 | | #include "dcmtk/oflog/helpers/strhelp.h" |
23 | | #include "dcmtk/oflog/helpers/timehelp.h" |
24 | | #include "dcmtk/oflog/spi/logevent.h" |
25 | | #include "dcmtk/oflog/helpers/property.h" |
26 | | #include "dcmtk/oflog/internal/internal.h" |
27 | | #include <ostream> |
28 | | #include <iomanip> |
29 | | |
30 | | |
31 | | namespace dcmtk |
32 | | { |
33 | | namespace log4cplus |
34 | | { |
35 | | |
36 | | void formatRelativeTimestamp (log4cplus::tostream & output, |
37 | | log4cplus::spi::InternalLoggingEvent const & event); |
38 | | |
39 | | void |
40 | | formatRelativeTimestamp (log4cplus::tostream & output, |
41 | | log4cplus::spi::InternalLoggingEvent const & event) |
42 | 0 | { |
43 | 0 | helpers::Time const rel_time |
44 | 0 | = event.getTimestamp () - getTTCCLayoutTimeBase (); |
45 | 0 | tchar const old_fill = output.fill (); |
46 | 0 | time_t const sec = rel_time.sec (); |
47 | | |
48 | 0 | if (sec != 0) |
49 | 0 | output << sec << STD_NAMESPACE setfill (DCMTK_LOG4CPLUS_TEXT ('0')) << STD_NAMESPACE setw (3); |
50 | | |
51 | 0 | output << rel_time.usec () / 1000; |
52 | 0 | output.fill (old_fill); |
53 | 0 | } |
54 | | |
55 | | // |
56 | | // |
57 | | // |
58 | | |
59 | | |
60 | | Layout::Layout () |
61 | 12 | : llmCache(getLogLevelManager()) |
62 | 12 | { } |
63 | | |
64 | | |
65 | | Layout::Layout (const log4cplus::helpers::Properties&) |
66 | 0 | : llmCache(getLogLevelManager()) |
67 | 0 | { } |
68 | | |
69 | | |
70 | | Layout::~Layout() |
71 | 6 | { } |
72 | | |
73 | | |
74 | | /////////////////////////////////////////////////////////////////////////////// |
75 | | // log4cplus::SimpleLayout public methods |
76 | | /////////////////////////////////////////////////////////////////////////////// |
77 | | |
78 | | SimpleLayout::SimpleLayout () |
79 | 6 | { } |
80 | | |
81 | | |
82 | | SimpleLayout::SimpleLayout (const helpers::Properties& properties) |
83 | 0 | : Layout (properties) |
84 | 0 | { } |
85 | | |
86 | | |
87 | | SimpleLayout::~SimpleLayout() |
88 | | { } |
89 | | |
90 | | |
91 | | void |
92 | | SimpleLayout::formatAndAppend(log4cplus::tostream& output, |
93 | | const log4cplus::spi::InternalLoggingEvent& event) |
94 | 0 | { |
95 | 0 | output << llmCache.toString(event.getLogLevel()) |
96 | 0 | << DCMTK_LOG4CPLUS_TEXT(" - ") |
97 | 0 | << event.getMessage() |
98 | 0 | << DCMTK_LOG4CPLUS_TEXT("\n"); |
99 | 0 | } |
100 | | |
101 | | |
102 | | |
103 | | /////////////////////////////////////////////////////////////////////////////// |
104 | | // log4cplus::TTCCLayout ctors and dtor |
105 | | /////////////////////////////////////////////////////////////////////////////// |
106 | | |
107 | | TTCCLayout::TTCCLayout(bool use_gmtime_) |
108 | 0 | : dateFormat() |
109 | 0 | , use_gmtime(use_gmtime_) |
110 | 0 | { |
111 | 0 | } |
112 | | |
113 | | |
114 | | TTCCLayout::TTCCLayout(const log4cplus::helpers::Properties& properties) |
115 | 0 | : Layout(properties) |
116 | 0 | , dateFormat(properties.getProperty (DCMTK_LOG4CPLUS_TEXT("DateFormat"), |
117 | 0 | internal::empty_str)) |
118 | 0 | , use_gmtime(false) |
119 | 0 | { |
120 | 0 | properties.getBool (use_gmtime, DCMTK_LOG4CPLUS_TEXT("Use_gmtime")); |
121 | 0 | } |
122 | | |
123 | | |
124 | | TTCCLayout::~TTCCLayout() |
125 | 0 | { } |
126 | | |
127 | | |
128 | | |
129 | | /////////////////////////////////////////////////////////////////////////////// |
130 | | // log4cplus::TTCCLayout public methods |
131 | | /////////////////////////////////////////////////////////////////////////////// |
132 | | |
133 | | void |
134 | | TTCCLayout::formatAndAppend(log4cplus::tostream& output, |
135 | | const log4cplus::spi::InternalLoggingEvent& event) |
136 | 0 | { |
137 | 0 | if (dateFormat.empty ()) |
138 | 0 | formatRelativeTimestamp (output, event); |
139 | 0 | else |
140 | 0 | output << event.getTimestamp().getFormattedTime(dateFormat, |
141 | 0 | use_gmtime); |
142 | |
|
143 | 0 | output << DCMTK_LOG4CPLUS_TEXT(" [") |
144 | 0 | << event.getThread() |
145 | 0 | << DCMTK_LOG4CPLUS_TEXT("] ") |
146 | 0 | << llmCache.toString(event.getLogLevel()) |
147 | 0 | << DCMTK_LOG4CPLUS_TEXT(" ") |
148 | 0 | << event.getLoggerName() |
149 | 0 | << DCMTK_LOG4CPLUS_TEXT(" <") |
150 | 0 | << event.getNDC() |
151 | 0 | << DCMTK_LOG4CPLUS_TEXT("> - ") |
152 | 0 | << event.getMessage() |
153 | 0 | << DCMTK_LOG4CPLUS_TEXT("\n"); |
154 | 0 | } |
155 | | |
156 | | |
157 | | } // namespace log4cplus |
158 | | } // end namespace dcmtk |