Back to Serial Studio

MDF Lib: include/mdf/mdflogstream.h Source File

lib/mdflib/docs/manual/html/mdflogstream_8h_source.html

3.2.77.8 KB
Original Source

| 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

20struct MdfLocation {

21int line = 0;

22int 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,

47MdfLogSeverity severity, const std::string &text)>;

48

53class MdfLogStream : public std::ostringstream {

54 public:

55MdfLogStream(MdfLocation location, MdfLogSeverity severity);

56~MdfLogStream() override;

57

58MdfLogStream() = delete;

59MdfLogStream(const MdfLogStream&) = delete;

60MdfLogStream(MdfLogStream&&) = delete;

61MdfLogStream& operator=(const MdfLogStream&) = delete;

62MdfLogStream& operator=(MdfLogStream&&) = delete;

63

65static void SetLogFunction1(const MdfLogFunction1& func);

67static void SetLogFunction2(const MdfLogFunction2& func);

68

69 protected:

70MdfLocation location_;

71MdfLogSeverity severity_;

72

74virtual void LogString(const MdfLocation& location, MdfLogSeverity severity,

75const std::string& text);

76};

77

78} // namespace mdf

mdf::MdfLogStream

MDF log stream interface.

Definition mdflogstream.h:53

mdf::MdfLogStream::LogString

virtual void LogString(const MdfLocation &location, MdfLogSeverity severity, const std::string &text)

Defines the logging function.

mdf::MdfLogStream::SetLogFunction1

static void SetLogFunction1(const MdfLogFunction1 &func)

Sets a log function.

mdf::MdfLogStream::location_

MdfLocation location_

File and function location.

Definition mdflogstream.h:70

mdf::MdfLogStream::severity_

MdfLogSeverity severity_

Log level of the stream.

Definition mdflogstream.h:71

mdf::MdfLogStream::SetLogFunction2

static void SetLogFunction2(const MdfLogFunction2 &func)

Sets a log function.

mdf::MdfLogStream::~MdfLogStream

~MdfLogStream() override

Destructor.

mdf::MdfLogStream::MdfLogStream

MdfLogStream(MdfLocation location, MdfLogSeverity severity)

Constructor.

mdffactory.h

Factory class for the MDF library.

mdf

Main namespace for the MDF library.

Definition canmessage.h:17

mdf::MdfLogFunction2

std::function< void(MdfLogSeverity severity, const std::string &function, const std::string &text)> MdfLogFunction2

MDF logging function definition.

Definition mdffactory.h:43

mdf::MdfLogSeverity

MdfLogSeverity

Defines the log severity level.

Definition mdffactory.h:30

mdf::MdfLogFunction1

std::function< void(const MdfLocation &location, MdfLogSeverity severity, const std::string &text)> MdfLogFunction1

MDF log function definition.

Definition mdflogstream.h:46

MdfLocation

This is a replacement for the std::source_location library. The standard source_location library cann...

Definition mdflogstream.h:20

MdfLocation::line

int line

Source code line.

Definition mdflogstream.h:21

MdfLocation::function

std::string function

Source code function.

Definition mdflogstream.h:24

MdfLocation::file

std::string file

Source code file name (avoid path).

Definition mdflogstream.h:23

MdfLocation::column

int column

Source code column.

Definition mdflogstream.h:22


Generated by 1.12.0