Coverage Report

Created: 2024-02-08 06:10

/src/opendnp3/cpp/lib/include/opendnp3/ConsoleLogger.h
Line
Count
Source
1
/*
2
 * Copyright 2013-2022 Step Function I/O, LLC
3
 *
4
 * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O
5
 * LLC (https://stepfunc.io) under one or more contributor license agreements.
6
 * See the NOTICE file distributed with this work for additional information
7
 * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license
8
 * this file to you under the Apache License, Version 2.0 (the "License"); you
9
 * may not use this file except in compliance with the License. You may obtain
10
 * a copy of the License at:
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
#ifndef OPENDNP3_CONSOLELOGGER_H
21
#define OPENDNP3_CONSOLELOGGER_H
22
23
#include "opendnp3/logging/ILogHandler.h"
24
#include "opendnp3/util/Uncopyable.h"
25
26
#include <memory>
27
#include <mutex>
28
29
namespace opendnp3
30
{
31
32
/**
33
 * LogHandler that prints all log messages to the console
34
 */
35
class ConsoleLogger final : public opendnp3::ILogHandler, private Uncopyable
36
{
37
38
public:
39
    void log(opendnp3::ModuleId module,
40
             const char* id,
41
             opendnp3::LogLevel level,
42
             char const* location,
43
             char const* message) final;
44
45
    static std::shared_ptr<opendnp3::ILogHandler> Create(bool printLocation = false)
46
8.53k
    {
47
8.53k
        return std::make_shared<ConsoleLogger>(printLocation);
48
8.53k
    };
49
50
8.53k
    ConsoleLogger(bool printLocation) : printLocation(printLocation) {}
51
52
private:
53
    bool printLocation;
54
55
    std::mutex mutex;
56
};
57
58
} // namespace opendnp3
59
60
#endif