Coverage Report

Created: 2025-11-11 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/strftimedateformat.cpp
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
#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
44
    timeZone(TimeZone::getDefault())
30
44
  {}
31
32
  /**
33
  *    Time zone.
34
  */
35
  TimeZonePtr timeZone;
36
  std::string pattern;
37
};
38
39
40
StrftimeDateFormat::StrftimeDateFormat(const LogString& fmt)
41
44
  : m_priv(std::make_unique<StrftimeDateFormatPrivate>())
42
44
{
43
44
  LOG4CXX_NS::helpers::Transcoder::encode(fmt, m_priv->pattern);
44
44
}
45
46
StrftimeDateFormat::~StrftimeDateFormat()
47
44
{
48
44
}
49
50
51
void StrftimeDateFormat::format(LogString& s, log4cxx_time_t time, Pool& /* p */ ) const
52
88
{
53
88
  apr_time_exp_t exploded;
54
88
  apr_status_t stat = m_priv->timeZone->explode(&exploded, time);
55
56
88
  if (stat == APR_SUCCESS)
57
88
  {
58
88
    const apr_size_t bufSize = 255;
59
88
    char buf[bufSize];
60
88
    apr_size_t bufLen;
61
88
    stat = apr_strftime(buf, &bufLen, bufSize, m_priv->pattern.c_str(), &exploded);
62
63
88
    if (stat == APR_SUCCESS)
64
88
    {
65
88
      LOG4CXX_NS::helpers::Transcoder::decode(std::string(buf, bufLen), s);
66
88
    }
67
88
  }
68
88
}
69
70
void StrftimeDateFormat::setTimeZone(const TimeZonePtr& zone)
71
40
{
72
40
  m_priv->timeZone = zone;
73
40
}
74
75