LogIt++
Loading...
Searching...
No Matches
LogStream.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _LOGIT_LOG_STREAM_HPP_INCLUDED
3#define _LOGIT_LOG_STREAM_HPP_INCLUDED
6
7#include <sstream>
8#include "Logger.hpp"
10
11namespace logit {
12
18 class LogStream {
19 public:
20
28 LogLevel level,
29 const std::string& file,
30 int line,
31 const std::string& function,
32 int logger_index)
33 : m_level(level), m_file(file), m_line(line), m_function(function),
34 m_logger_index(logger_index) {
35 }
36
43 // Automatically log when the LogStream object is destroyed (end of line).
47 m_stream.str(), std::string(), // No argument names for stream-based logs.
49 false
50 });
51 }
52
57 template <typename T>
58 LogStream& operator<<(const T& value) {
59 m_stream << value;
60 return *this;
61 }
62
63 // Перегрузка оператора << для манипуляторов (например, std::endl)
64 LogStream& operator<<(std::ostream& (*manip)(std::ostream&)) {
65 m_stream << manip; // Применяем манипулятор к внутреннему потоку
66 return *this;
67 }
68
69 private:
71 std::ostringstream m_stream;
72 std::string m_file;
73 int m_line;
74 std::string m_function;
76 };
77
78} // namespace logit
79
80#endif // _LOGIT_LOG_STREAM_HPP_INCLUDED
Defines the Logger class for managing multiple loggers and formatters.
A stream-based logger that collects log messages using the << operator.
Definition LogStream.hpp:18
LogStream & operator<<(const T &value)
Overloaded << operator to accumulate log content.
Definition LogStream.hpp:58
LogLevel m_level
Log level.
Definition LogStream.hpp:70
int m_logger_index
Logger index.
Definition LogStream.hpp:75
int m_line
Line number.
Definition LogStream.hpp:73
std::ostringstream m_stream
Stream for accumulating log content.
Definition LogStream.hpp:71
std::string m_file
Source file name.
Definition LogStream.hpp:72
std::string m_function
Function name.
Definition LogStream.hpp:74
~LogStream()
Destructor that logs the collected message when the object goes out of scope.
Definition LogStream.hpp:42
LogStream & operator<<(std::ostream &(*manip)(std::ostream &))
Definition LogStream.hpp:64
LogStream(LogLevel level, const std::string &file, int line, const std::string &function, int logger_index)
Constructor.
Definition LogStream.hpp:27
auto log_and_return(const LogRecord &record, Ts &&... args) -> decltype(std::forward_as_tuple(std::forward< Ts >(args)...))
Logs the message and returns a tuple of arguments.
Definition Logger.hpp:164
static Logger & get_instance()
Retrieves the singleton instance of Logger.
Definition Logger.hpp:26
#define LOGIT_CURRENT_TIMESTAMP_MS()
Macro to get the current timestamp in milliseconds. If LOGIT_CURRENT_TIMESTAMP_MS is not defined,...
The primary namespace for the LogIt++ library.
LogLevel
Logging levels.
Definition Enums.hpp:14
Utility functions for path manipulation, including relative path computation.
Stores log metadata and content.
Definition LogRecord.hpp:15