• 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

43.48
/libs/core/logging/src/format/destination/file.cpp
1
// destination_file.hpp
2

3
// Boost Logging library
4
//
5
// Author: John Torjo, www.torjo.com
6
//
7
// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
8
//
9
//  SPDX-License-Identifier: BSL-1.0
10
// Distributed under the Boost Software License, Version 1.0.
11
//    (See accompanying file LICENSE_1_0.txt or copy at
12
//          http://www.boost.org/LICENSE_1_0.txt)
13
//
14
// See http://www.boost.org for updates, documentation, and revision history.
15
// See http://www.torjo.com/log2/ for more details
16

17
#include <hpx/config.hpp>
18
#include <hpx/logging/format/destinations.hpp>
19
#include <hpx/logging/message.hpp>
20
#include <hpx/modules/thread_support.hpp>
21

22
#include <fstream>
23
#include <memory>
24
#include <mutex>
25
#include <string>
26

27
namespace hpx::util::logging::destination {
28

29
    file::~file() = default;
30

832✔
31
    static std::ios_base::openmode open_flags(file::file_settings fs)
32
    {
33
        std::ios_base::openmode flags = std::ios_base::out;
34
        flags |= fs.extra_flags;
35
        if (fs.do_append && !fs.initial_overwrite)
36
            flags |= std::ios_base::app;
×
37
        if (fs.initial_overwrite)
38
            flags |= std::ios_base::trunc;
×
39
        return flags;
40
    }
41

42
    struct file_impl final : file
43
    {
44
        typedef hpx::util::detail::spinlock mutex_type;
45

46
        explicit file_impl(std::string file_name, file_settings set)
47
          : file(HPX_MOVE(file_name), set)
832✔
48
        {
1,664✔
49
        }
50

832✔
51
        void operator()(message const& msg) override
52
        {
×
53
            std::lock_guard<mutex_type> l(mtx_);
54

×
55
            open();    // make sure file is opened
56
            out << msg.full_string();
×
57
            if (settings.flush_each_time)
×
58
                out.flush();
×
59
        }
×
60

×
61
        /** configure through script
62
            right now, you can only specify the file name
63
        */
64
        void configure(std::string const& str) override
65
        {
64✔
66
            // configure - the file name, for now
67
            close();
68
            name = str;
69
        }
64✔
70

64✔
71
    private:
72
        void open()
73
        {
×
74
            if (!out.is_open())
75
                out.open(name.c_str(), open_flags(settings));
×
76
        }
×
77

×
78
        void close()
79
        {
80
            out.close();
81
        }
64✔
82

83
        std::ofstream out;
84
        mutable mutex_type mtx_;
85
    };
86

87
    std::unique_ptr<file> file::make(
88
        std::string const& file_name, file_settings set)
832✔
89
    {
90
        return std::make_unique<file_impl>(file_name, set);
91
    }
832✔
92
}    // namespace hpx::util::logging::destination
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

© 2026 Coveralls, Inc