blob: d90b2df4758e9161873a941ab183ecbb564282db [file] [log] [blame]
Shawn McCarneyaaa4fdd2021-03-18 19:32:37 -05001/**
2 * Copyright © 2021 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#pragma once
17
18#include "error_history.hpp"
19#include "error_logging.hpp"
20#include "services.hpp"
21
22#include <exception>
23
24/**
25 * @namespace error_logging_utils
26 *
27 * Contains utility functions for logging errors.
28 */
29namespace phosphor::power::regulators::error_logging_utils
30{
31
32/**
33 * Logs an error based on the specified exception and any nested inner
34 * exceptions.
35 *
36 * @param eptr exception pointer
37 * @param severity severity level
38 * @param services system services like error logging and the journal
39 */
40void logError(std::exception_ptr eptr, Entry::Level severity,
41 Services& services);
42
43/**
44 * Logs an error, if necessary, based on the specified exception and any nested
45 * inner exceptions.
46 *
47 * Finds the error type would be logged based on the specified exception and any
48 * nested inner exceptions.
49 *
50 * Checks to see if this error type has already been logged according to the
51 * specified ErrorHistory object.
52 *
53 * If the error type has not been logged, an error log entry is created, and the
54 * ErrorHistory is updated.
55 *
56 * If the error type has been logged, no further action is taken.
57 *
58 * @param eptr exception pointer
59 * @param severity severity level
60 * @param services system services like error logging and the journal
61 * @param history error logging history
62 */
63void logError(std::exception_ptr eptr, Entry::Level severity,
64 Services& services, ErrorHistory& history);
65
66/*
67 * Internal implementation details
68 */
69namespace internal
70{
71
72/**
73 * Returns the exception to use when logging an error.
74 *
75 * Inspects the specified exception and any nested inner exceptions. Returns
76 * the highest priority exception from an error logging perspective.
77 *
78 * @param eptr exception pointer
79 * @return exception to log
80 */
81std::exception_ptr getExceptionToLog(std::exception_ptr eptr);
82
83} // namespace internal
84
85} // namespace phosphor::power::regulators::error_logging_utils