summaryrefslogtreecommitdiff
path: root/include/CommonAPI/LoggerImpl.hpp
blob: 1c69d875674945a6a2d7769587f0cdb47ad6f095 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef COMMONAPI_LOGGER_IMPL_HPP_
#define COMMONAPI_LOGGER_IMPL_HPP_

#ifdef USE_DLT
#include <dlt/dlt.h>
#endif

#include <cstdint>
#include <fstream>
#include <memory>
#include <mutex>
#include <sstream>

#include <CommonAPI/Export.hpp>


namespace CommonAPI {

class Logger;

class LoggerImpl {
public:
    friend class Logger;

    enum class Level : uint8_t COMMONAPI_EXPORT {
      LL_FATAL = 0, LL_ERROR = 1, LL_WARNING = 2, LL_INFO = 3, LL_DEBUG = 4, LL_VERBOSE = 5
    };

    static void init(bool, const std::string &, bool, const std::string &);

private:

  LoggerImpl();
  ~LoggerImpl();

  COMMONAPI_EXPORT static bool isLogged(Level _level);
    
  COMMONAPI_EXPORT static LoggerImpl* get();

  COMMONAPI_EXPORT void doLog(Level _level, const std::string &_message);

#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
    static Level stringAsLevel(const std::string &_level);
#endif
#if defined(USE_CONSOLE) || defined(USE_FILE)
    static std::string levelAsString(Level _level);
#endif
#ifdef USE_DLT
    static DltLogLevelType levelAsDlt(Level _level);
#endif
#if defined(USE_CONSOLE) || defined(USE_FILE)
    static std::mutex mutex_;
#endif
#if defined(USE_CONSOLE) || defined(USE_FILE) || defined(USE_DLT)
    static Level maximumLogLevel_;
#endif
#ifdef USE_CONSOLE
    static bool useConsole_;
#endif
#ifdef USE_FILE
    static std::shared_ptr<std::ofstream> file_;
#endif
#ifdef USE_DLT
    static bool useDlt_;
    DLT_DECLARE_CONTEXT(dlt_);
    bool ownAppID_;
#endif
};

} // namespace CommonAPI

#endif // COMMONAPI_LOGGER_IMPL_HPP_