MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
mdflogstream.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
5
11#pragma once
12
13#include <sstream>
14#include <string>
15
21 int line = 0;
22 int column = 0;
23 std::string file;
24 std::string function;
25};
26
27#include "mdf/mdffactory.h"
28
29namespace mdf {
30
31
32#define MDF_TRACE() \
33 MdfLogStream({__LINE__,0,__FILE__,__func__}, \
34 MdfLogSeverity::kTrace)
35#define MDF_DEBUG() \
36 MdfLogStream({__LINE__,0,__FILE__,__func__}, \
37 MdfLogSeverity::kDebug)
38#define MDF_INFO() \
39 MdfLogStream({__LINE__,0,__FILE__,__func__}, \
40 MdfLogSeverity::kInfo)
41#define MDF_ERROR() \
42 MdfLogStream({__LINE__,0,__FILE__,__func__}, \
43 MdfLogSeverity::kError)
44
46using MdfLogFunction1 = std::function<void(const MdfLocation &location,
47 MdfLogSeverity severity, const std::string &text)>;
48
53class MdfLogStream : public std::ostringstream {
54 public:
56 ~MdfLogStream() override;
57
58 MdfLogStream() = delete;
59 MdfLogStream(const MdfLogStream&) = delete;
60 MdfLogStream(MdfLogStream&&) = delete;
61 MdfLogStream& operator=(const MdfLogStream&) = delete;
62 MdfLogStream& operator=(MdfLogStream&&) = delete;
63
65 static void SetLogFunction1(const MdfLogFunction1& func);
67 static void SetLogFunction2(const MdfLogFunction2& func);
68
69 protected:
72
74 virtual void LogString(const MdfLocation& location, MdfLogSeverity severity,
75 const std::string& text);
76};
77
78} // namespace mdf
MDF log stream interface.
Definition mdflogstream.h:53
virtual void LogString(const MdfLocation &location, MdfLogSeverity severity, const std::string &text)
Defines the logging function.
static void SetLogFunction1(const MdfLogFunction1 &func)
Sets a log function.
MdfLocation location_
File and function location.
Definition mdflogstream.h:70
MdfLogSeverity severity_
Log level of the stream.
Definition mdflogstream.h:71
static void SetLogFunction2(const MdfLogFunction2 &func)
Sets a log function.
~MdfLogStream() override
Destructor.
MdfLogStream(MdfLocation location, MdfLogSeverity severity)
Constructor.
Factory class for the MDF library.
Main namespace for the MDF library.
Definition canmessage.h:17
std::function< void(MdfLogSeverity severity, const std::string &function, const std::string &text)> MdfLogFunction2
MDF logging function definition.
Definition mdffactory.h:43
MdfLogSeverity
Defines the log severity level.
Definition mdffactory.h:30
std::function< void(const MdfLocation &location, MdfLogSeverity severity, const std::string &text)> MdfLogFunction1
MDF log function definition.
Definition mdflogstream.h:46
This is a replacement for the std::source_location library. The standard source_location library cann...
Definition mdflogstream.h:20
int line
Source code line.
Definition mdflogstream.h:21
std::string function
Source code function.
Definition mdflogstream.h:24
std::string file
Source code file name (avoid path).
Definition mdflogstream.h:23
int column
Source code column.
Definition mdflogstream.h:22