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 const LogLevel& level,
29 const std::string& file,
30 const int& line,
31 const std::string& function,
32 const 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 private:
65 std::ostringstream m_stream;
66 std::string m_file;
67 int m_line;
68 std::string m_function;
70 };
71
72} // namespace logit
73
74#endif // _LOGIT_LOG_STREAM_HPP_INCLUDED
#define LOGIT_CURRENT_TIMESTAMP_MS()
Macro to get the current timestamp in milliseconds. If LOGIT_CURRENT_TIMESTAMP_MS is not defined,...
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
LogStream(const LogLevel &level, const std::string &file, const int &line, const std::string &function, const int &logger_index)
Constructor.
Definition LogStream.hpp:27
LogLevel m_level
Log level.
Definition LogStream.hpp:64
int m_logger_index
Logger index.
Definition LogStream.hpp:69
int m_line
Line number.
Definition LogStream.hpp:67
std::ostringstream m_stream
Stream for accumulating log content.
Definition LogStream.hpp:65
std::string m_file
Source file name.
Definition LogStream.hpp:66
std::string m_function
Function name.
Definition LogStream.hpp:68
~LogStream()
Destructor that logs the collected message when the object goes out of scope.
Definition LogStream.hpp:42
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:117
static Logger & get_instance()
Retrieves the singleton instance of Logger.
Definition Logger.hpp:26
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