Coverage Report

Created: 2025-07-01 06:08

/src/logging-log4cxx/src/main/cpp/strftimedateformat.cpp
Line
Count
Source (jump to first uncovered line)
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
#include <log4cxx/logstring.h>
19
#include <log4cxx/helpers/strftimedateformat.h>
20
21
#include <apr_time.h>
22
#include <log4cxx/helpers/transcoder.h>
23
24
using namespace LOG4CXX_NS;
25
using namespace LOG4CXX_NS::helpers;
26
27
struct StrftimeDateFormat::StrftimeDateFormatPrivate{
28
  StrftimeDateFormatPrivate() :
29
0
    timeZone(TimeZone::getDefault())
30
0
  {}
31
32
  /**
33
  *    Time zone.
34
  */
35
  TimeZonePtr timeZone;
36
  std::string pattern;
37
};
38
39
40
StrftimeDateFormat::StrftimeDateFormat(const LogString& fmt)
41
0
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
0
{
43
0
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
0
}
45
46
StrftimeDateFormat::~StrftimeDateFormat()
47
0
{
48
0
}
49
50
51
void StrftimeDateFormat::format(LogString& s, log4cxx_time_t time, Pool& /* p */ ) const
52
0
{
53
0
  apr_time_exp_t exploded;
54
0
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
0
  if (stat == APR_SUCCESS)
57
0
  {
58
0
    const apr_size_t bufSize = 255;
59
0
    char buf[bufSize];
60
0
    apr_size_t bufLen;
61
0
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
0
    if (stat == APR_SUCCESS)
64
0
    {
65
0
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
0
    }
67
0
  }
68
0
}
69
70
void StrftimeDateFormat::setTimeZone(const TimeZonePtr& zone)
71
0
{
72
0
  m_priv->timeZone = zone;
73
0
}
74
75