Create a class to store messages for event log
Create a Logger class that can store log messages along with their
timestamps. These messages will then be added to an event log when they
are created for missing fans, for debug purposes. Each message is also
logged to the journal.
The maximum number of entries to keep around is specified in the
constructor, and when full the oldest message will be purged when new
ones are added. This number comes from a configuration option which
defaults to 50.
A standalone getLogger() API was also added to give the new object
singleton behavior, so the same object can be accessed from all classes
in an application.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I8d5ac137acb67bfe78609d02aaf59a01b03c5c8b
diff --git a/presence/Makefile.am b/presence/Makefile.am
index a26fac9..af66bbd 100644
--- a/presence/Makefile.am
+++ b/presence/Makefile.am
@@ -10,6 +10,7 @@
fallback.cpp \
fan.cpp \
gpio.cpp \
+ logging.cpp \
psensor.cpp \
tach.cpp \
tach_detect.cpp \
diff --git a/presence/logging.cpp b/presence/logging.cpp
new file mode 100644
index 0000000..3945ac9
--- /dev/null
+++ b/presence/logging.cpp
@@ -0,0 +1,30 @@
+/**
+ * Copyright © 2020 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "config.h"
+
+#include "logging.hpp"
+
+namespace phosphor::fan
+{
+
+Logger& getLogger()
+{
+ static Logger logger{NUM_PRESENCE_LOG_ENTRIES};
+
+ return logger;
+}
+
+} // namespace phosphor::fan
diff --git a/presence/logging.hpp b/presence/logging.hpp
new file mode 100644
index 0000000..dd75a96
--- /dev/null
+++ b/presence/logging.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "logger.hpp"
+
+namespace phosphor::fan
+{
+/**
+ * @brief Returns the singleton Logger class
+ *
+ * @return Logger& - The logger
+ */
+Logger& getLogger();
+} // namespace phosphor::fan