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
4
7
8#include <sstream>
9#include "Logger.hpp"
10#include "utils/path_utils.hpp"
11
12namespace logit {
13
19 class LogStream {
20 public:
21
29 LogLevel level,
30 const std::string& file,
31 int line,
32 const std::string& function,
33 int logger_index)
34 : m_level(level), m_file(file), m_line(line), m_function(function),
35 m_logger_index(logger_index) {
36 }
37
44 // Automatically log when the LogStream object is destroyed (end of line).
48 m_stream.str(), std::string(), // No argument names for stream-based logs.
50 false
51 });
52 }
53
58 template <typename T>
59 LogStream& operator<<(const T& value) {
60 m_stream << value;
61 return *this;
62 }
63
64 // Overload of operator<< for manipulators (e.g., std::endl)
65 LogStream& operator<<(std::ostream& (*manip)(std::ostream&)) {
66 m_stream << manip; // Apply the manipulator to the internal stream
67 return *this;
68 }
69
70 private:
72 std::ostringstream m_stream;
73 std::string m_file;
74 int m_line;
75 std::string m_function;
77 };
78
79} // namespace logit
80
81#endif // _LOGIT_LOG_STREAM_HPP_INCLUDED
#define LOGIT_CURRENT_TIMESTAMP_MS()
Macro to get the current timestamp in milliseconds.
Defines the Logger class for managing multiple loggers and formatters.
LogStream & operator<<(const T &value)
Overloaded << operator to accumulate log content.
Definition LogStream.hpp:59
LogLevel m_level
Log level.
Definition LogStream.hpp:71
int m_logger_index
Logger index.
Definition LogStream.hpp:76
int m_line
Line number.
Definition LogStream.hpp:74
std::ostringstream m_stream
Stream for accumulating log content.
Definition LogStream.hpp:72
std::string m_file
Source file name.
Definition LogStream.hpp:73
std::string m_function
Function name.
Definition LogStream.hpp:75
~LogStream()
Destructor that logs the collected message when the object goes out of scope.
Definition LogStream.hpp:43
LogStream & operator<<(std::ostream &(*manip)(std::ostream &))
Definition LogStream.hpp:65
LogStream(LogLevel level, const std::string &file, int line, const std::string &function, int logger_index)
Constructor.
Definition LogStream.hpp:28
auto log_and_return(const LogRecord &record, Ts &&... args) -> decltype(std::forward_as_tuple(std::forward< Ts >(args)...))
Logs message and returns tuple of arguments.
Definition Logger.hpp:199
static Logger & get_instance()
Retrieves singleton instance of Logger.
Definition Logger.hpp:28
The primary namespace for the LogIt++ library.
LogLevel
Logging levels.
Definition enums.hpp:15
Utility functions for path manipulation, including relative path computation.
Stores log metadata and content.
Definition LogRecord.hpp:17