new file mode 100644
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2018, Google Inc.
+ *
+ * log.h - Logging infrastructure
+ */
+#ifndef __LIBCAMERA_LOGGING_H__
+#define __LIBCAMERA_LOGGING_H__
+
+namespace libcamera {
+
+void logSetFile(const char *file);
+void logSetLevel(const char *category, const char *level);
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_LOGGING_H__ */
@@ -9,6 +9,7 @@ libcamera_api = files([
'geometry.h',
'ipa/ipa_interface.h',
'ipa/ipa_module_info.h',
+ 'logging.h',
'object.h',
'request.h',
'signal.h',
@@ -69,6 +69,9 @@ private:
void parseLogLevels();
static LogSeverity parseLogLevel(const std::string &level);
+ friend void logSetFile(const char *file);
+ friend void logSetLevel(const char *category, const char *level);
+
friend LogCategory;
void registerCategory(LogCategory *category);
void unregisterCategory(LogCategory *category);
@@ -80,6 +83,35 @@ private:
std::ostream *output_;
};
+void logSetFile(const char *file)
+{
+ if (std::string(file).empty())
+ return;
+
+ Logger *logger = Logger::instance();
+ std::ofstream &file_ = logger->file_;
+ file_.close();
+ file_.open(file);
+ if (file_.good())
+ logger->output_ = &file_;
+}
+
+void logSetLevel(const char *category, const char *level)
+{
+ std::string cat(category);
+ std::string lev(level);
+
+ /* Both the category and the level must be specified. */
+ if (cat.empty() || lev.empty())
+ return;
+
+ LogSeverity severity = Logger::parseLogLevel(lev);
+ if (severity == LogInvalid)
+ return;
+
+ Logger::instance()->levels_.push_back({ cat, severity });
+}
+
/**
* \brief Retrieve the logger instance
*
Currently the log file and the log level can only be set via environment variables, but applications may also want to set the log file and the log level at run time. Provide an API for this. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> --- include/libcamera/logging.h | 17 +++++++++++++++++ include/libcamera/meson.build | 1 + src/libcamera/log.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 include/libcamera/logging.h