Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "mock_journal.hpp" |
| 18 | |
| 19 | /** |
| 20 | * This is the mock implementation of the journal interface. It just stores the |
| 21 | * journal messages in static vectors. |
| 22 | * |
| 23 | * Executables that need to log real systemd journal messages should link with |
| 24 | * the file journal.cpp instead. |
| 25 | */ |
| 26 | namespace phosphor::power::regulators::journal |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * Mock journal messages with a priority value of 'ERR'. |
| 31 | */ |
| 32 | static std::vector<std::string> errMessages{}; |
| 33 | |
| 34 | /** |
| 35 | * Mock journal messages with a priority value of 'INFO'. |
| 36 | */ |
| 37 | static std::vector<std::string> infoMessages{}; |
| 38 | |
Shawn McCarney | 9af8555 | 2020-04-09 11:43:48 -0500 | [diff] [blame] | 39 | /** |
| 40 | * Mock journal messages with a priority value of 'DEBUG'. |
| 41 | */ |
| 42 | static std::vector<std::string> debugMessages{}; |
| 43 | |
Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 44 | void clear() |
| 45 | { |
| 46 | errMessages.clear(); |
| 47 | infoMessages.clear(); |
Shawn McCarney | 9af8555 | 2020-04-09 11:43:48 -0500 | [diff] [blame] | 48 | debugMessages.clear(); |
Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | const std::vector<std::string>& getErrMessages() |
| 52 | { |
| 53 | return errMessages; |
| 54 | } |
| 55 | |
| 56 | const std::vector<std::string>& getInfoMessages() |
| 57 | { |
| 58 | return infoMessages; |
| 59 | } |
| 60 | |
Shawn McCarney | 9af8555 | 2020-04-09 11:43:48 -0500 | [diff] [blame] | 61 | const std::vector<std::string>& getDebugMessages() |
| 62 | { |
| 63 | return debugMessages; |
| 64 | } |
| 65 | |
Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 66 | void logErr(const std::string& message) |
| 67 | { |
| 68 | errMessages.emplace_back(message); |
| 69 | } |
| 70 | |
| 71 | void logInfo(const std::string& message) |
| 72 | { |
| 73 | infoMessages.emplace_back(message); |
| 74 | } |
| 75 | |
Shawn McCarney | 9af8555 | 2020-04-09 11:43:48 -0500 | [diff] [blame] | 76 | void logDebug(const std::string& message) |
| 77 | { |
| 78 | debugMessages.emplace_back(message); |
| 79 | } |
| 80 | |
Shawn McCarney | 7c5d7b2 | 2020-04-03 18:50:13 -0500 | [diff] [blame] | 81 | } // namespace phosphor::power::regulators::journal |