File: logger.hpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (175 lines) | stat: -rw-r--r-- 4,698 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/************************************************************************
 *
 * Copyright (C) 2009-2024 IRCAD France
 * Copyright (C) 2012-2019 IHU Strasbourg
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#pragma once

#include <sight/core/config.hpp>

#include "core/log/log.hpp"

#include <core/object.hpp>

#include <string>

namespace sight::core::log
{

/**
 * @brief Logger class used to store logs
 */
class SIGHT_CORE_CLASS_API logger : public core::object
{
public:

    SIGHT_DECLARE_CLASS(logger, core::object);

    using log_container_t             = std::vector<core::log::log>;
    using iterator_type               = log_container_t::iterator;
    using const_iterator_type         = log_container_t::const_iterator;
    using reverse_iterator_type       = log_container_t::reverse_iterator;
    using const_reverse_iterator_type = log_container_t::const_reverse_iterator;

    /// Constructor
    SIGHT_CORE_API logger();

    /// Destructor
    SIGHT_CORE_API ~logger() override;

    /**
     * @brief Add information log into the logger
     * @param[in] _message Log message
     */
    SIGHT_CORE_API void information(const std::string& _message);

    /**
     * @brief Add warning log into the logger
     * @param[in] _message Log message
     */
    SIGHT_CORE_API void warning(const std::string& _message);

    /**
     * @brief Add critical log into the logger
     * @param[in] _message Log message
     */
    SIGHT_CORE_API void critical(const std::string& _message);

    /**
     * @brief Return the log matching the specified index
     * @param[in] _index Log's index
     */
    SIGHT_CORE_API core::log::log get_log(unsigned int _index);

    /// Returns the number of logs
    SIGHT_CORE_API std::size_t count() const;

    /**
     * @brief Return the number of logs matching the specified level
     * @param[in] _level Log level
     */
    SIGHT_CORE_API std::size_t count(core::log::log::level_t _level) const;

    /**
     * @brief Sort logs according to log levels
     */
    SIGHT_CORE_API void sort();

    /**
     * @brief Clear logs
     */
    SIGHT_CORE_API void clear();

    /// Return whether the logger contains logs or not
    bool empty() const
    {
        return m_log_container.empty();
    }

    //------------------------------------------------------------------------------

    iterator_type begin()
    {
        return m_log_container.begin();
    }

    //------------------------------------------------------------------------------

    iterator_type end()
    {
        return m_log_container.end();
    }

    //------------------------------------------------------------------------------

    const_iterator_type begin() const
    {
        return m_log_container.begin();
    }

    //------------------------------------------------------------------------------

    const_iterator_type end() const
    {
        return m_log_container.end();
    }

    //------------------------------------------------------------------------------

    reverse_iterator_type rbegin()
    {
        return m_log_container.rbegin();
    }

    //------------------------------------------------------------------------------

    reverse_iterator_type rend()
    {
        return m_log_container.rend();
    }

    //------------------------------------------------------------------------------

    const_reverse_iterator_type rbegin() const
    {
        return m_log_container.rbegin();
    }

    //------------------------------------------------------------------------------

    const_reverse_iterator_type rend() const
    {
        return m_log_container.rend();
    }

protected:

    /**
     * @brief Function used to sort logs
     * @param _log_a First log
     * @param _log_b Second log
     */
    static bool log_sorter(const core::log::log& _log_a, const core::log::log& _log_b);

    /// Log container
    log_container_t m_log_container;
}; // class logger

} // namespace sight::core::log