• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.52
/libs/full/init_runtime/src/init_logging.cpp
1
//  Copyright (c) 2021 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8

9
#if defined(HPX_HAVE_LOGGING)
10
#include <hpx/init_runtime/detail/init_logging.hpp>
11
#include <hpx/modules/logging.hpp>
12
#include <hpx/modules/runtime_configuration.hpp>
13

14
#if defined(HPX_HAVE_DISTRIBUTED_RUNTIME)
15
#include <hpx/modules/threading_base.hpp>
16
#include <hpx/runtime_components/console_logging.hpp>
17
#endif
18

19
#include <cstddef>
20
#include <cstdint>
21
#include <cstdlib>
22
#include <ostream>
23
#include <string>
24

25
///////////////////////////////////////////////////////////////////////////////
26
namespace hpx { namespace util {
27

28
#if defined(HPX_HAVE_DISTRIBUTED_RUNTIME)
29
    ///////////////////////////////////////////////////////////////////////////
30
    // custom formatter: HPX component id of current thread
31
    struct thread_component_id : logging::formatter::manipulator
64✔
32
    {
33
        void operator()(std::ostream& to) const override
×
34
        {
35
            std::uint64_t component_id = threads::get_self_component_id();
×
36
            if (0 != component_id)
×
37
            {
38
                // called from inside a HPX thread
39
                util::format_to(to, "{:016x}", component_id);
×
40
            }
41
            else
42
            {
43
                // called from outside a HPX thread
44
                to << std::string(16, '-');
×
45
            }
46
        }
×
47
    };
48

49
    ///////////////////////////////////////////////////////////////////////////
50
    // custom log destination: send generated strings to console
51
    struct console : console_local
64✔
52
    {
53
        console(logging::level level, logging_destination dest)
54
          : console_local(level, dest)
64✔
55
        {
56
        }
57

58
        void operator()(logging::message const& msg) override
×
59
        {
60
            components::console_logging(
×
61
                dest_, static_cast<std::size_t>(level_), msg.full_string());
×
62
        }
×
63
    };    // namespace util
64
#else
65
    using console = console_local;
66
#endif
67

68
    namespace detail {
69

70
        void get_console(logging::writer::named_write& writer, char const* name,
64✔
71
            logging::level lvl, logging_destination dest)
72
        {
73
            writer.set_destination(name, console(lvl, dest));
128✔
74
        }
64✔
75

76
        void define_formatters(logging::writer::named_write& writer)
64✔
77
        {
78
            define_common_formatters(writer);
64✔
79

80
#if defined(HPX_HAVE_DISTRIBUTED_RUNTIME)
81
            writer.set_formatter("hpxcomponent", thread_component_id());
128✔
82
#endif
83
        }
64✔
84

85
        void init_logging_full(runtime_configuration& ini)
32✔
86
        {
87
            init_logging(ini, ini.mode_ == runtime_mode::console, get_console,
32✔
88
                define_formatters);
89
        }
32✔
90
    }    // namespace detail
91
}}    // namespace hpx::util
92

93
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc