/src/opendnp3/cpp/lib/src/ConsoleLogger.cpp
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 | | #include "opendnp3/ConsoleLogger.h" |
21 | | |
22 | | #include "logging/ConsolePrettyPrinter.h" |
23 | | |
24 | | #include "opendnp3/logging/LogLevels.h" |
25 | | |
26 | | #include <cassert> |
27 | | #include <chrono> |
28 | | #include <iostream> |
29 | | #include <sstream> |
30 | | |
31 | | namespace opendnp3 |
32 | | { |
33 | | |
34 | | void ConsoleLogger::log(ModuleId module, const char* id, LogLevel level, char const* location, char const* message) |
35 | 0 | { |
36 | 0 | auto time = std::chrono::high_resolution_clock::now(); |
37 | 0 | auto num = std::chrono::duration_cast<std::chrono::milliseconds>(time.time_since_epoch()).count(); |
38 | |
|
39 | 0 | std::ostringstream oss; |
40 | |
|
41 | 0 | oss << "ms(" << num << ") " << LogFlagToString(level); |
42 | 0 | oss << " " << id; |
43 | 0 | if (printLocation) |
44 | 0 | { |
45 | 0 | oss << " - " << location; |
46 | 0 | } |
47 | 0 | oss << " - " << message; |
48 | |
|
49 | 0 | std::unique_lock<std::mutex> lock(mutex); |
50 | 0 | std::cout << oss.str() << std::endl; |
51 | 0 | } |
52 | | |
53 | | } // namespace opendnp3 |