AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
stream.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-log-export.hpp"
23
24#include <optional>
25#include <ostream>
26#include <sstream>
27#include <string>
28
29#include "log/levels.hpp"
30#include "log/logger.hpp"
31
32namespace anch::log {
33
45 template<anch::log::Level L>
46 struct LevelTag {
48 static constexpr anch::log::Level value = L;
49 };
50
60 class ANCH_LOG_EXPORT NoopStream {
61
62 // Methods +
63 public:
69 template<typename T>
70 constexpr const NoopStream& operator<<(const T&) const noexcept;
71
77 constexpr const NoopStream& operator<<(std::ostream& (*)(std::ostream&)) const noexcept;
78 // Methods -
79
80 };
81
97 class ANCH_LOG_EXPORT LogLine {
98
99 // Attributes +
100 private:
102 const anch::log::Logger& _logger;
103
105 anch::log::Level _level;
106
108 std::optional<std::ostringstream> _out;
109 // Attributes -
110
111 // Constructors +
112 public:
119 LogLine(const anch::log::Logger& logger, anch::log::Level level) noexcept;
120
122 LogLine(const LogLine&) = delete;
123
125 LogLine(LogLine&&) = delete;
126 // Constructors -
127
128 // Destructor +
129 public:
133 ~LogLine() noexcept;
134 // Destructor -
135
136 // Methods +
137 public:
145 template<typename T>
146 LogLine& operator<<(const T& value) noexcept;
147
155 LogLine& operator<<(std::ostream& (*manip)(std::ostream&)) noexcept;
156
160 LogLine& operator=(const LogLine&) = delete;
161
165 LogLine& operator=(LogLine&&) = delete;
166 // Methods -
167
168 };
169
181 template<anch::log::Level L>
182 [[nodiscard]] auto operator<<(const anch::log::Logger& logger, anch::log::LevelTag<L> level) noexcept;
183
184}
185
186namespace anch::log::lvl {
187
190
193
196
199
202
205
206}
207
208#include "log/impl/stream.hpp"
LogLine(const anch::log::Logger &logger, anch::log::Level level) noexcept
LogLine(LogLine &&)=delete
~LogLine() noexcept
LogLine(const LogLine &)=delete
Definition logger.hpp:47
Definition stream.hpp:60
constexpr const NoopStream & operator<<(std::ostream &(*)(std::ostream &)) const noexcept
constexpr const NoopStream & operator<<(const T &) const noexcept
Logging levels as types for the stream API.
constexpr anch::log::LevelTag< anch::log::Level::ERROR > error
Definition stream.hpp:201
constexpr anch::log::LevelTag< anch::log::Level::WARN > warn
Definition stream.hpp:198
constexpr anch::log::LevelTag< anch::log::Level::FATAL > fatal
Definition stream.hpp:204
constexpr anch::log::LevelTag< anch::log::Level::DEBUG > debug
Definition stream.hpp:192
constexpr anch::log::LevelTag< anch::log::Level::INFO > info
Definition stream.hpp:195
constexpr anch::log::LevelTag< anch::log::Level::TRACE > trace
Definition stream.hpp:189
AnCH logging library namespace.
Definition constants.hpp:26
Level
Definition levels.hpp:43
AnCH framework base namespace.
Definition app.hpp:30
Definition stream.hpp:46
static constexpr anch::log::Level value
Definition stream.hpp:48