pw_log: Move configurable macros to options.h
- Move configurable macros (PW_LOG_MODULE_NAME, PW_LOG_LEVEL, etc.) to
pw_log/options.h. This avoids potential circular dependencies when
implementing pw_log.
- Have pw_log_tokenized include pw_log/options.h instead of
pw_log/log.h.
Change-Id: I800b8bb2794b05913e01974e5d267ee9dcc508cc
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/15582
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_log/BUILD b/pw_log/BUILD
index 312c202..ec768fe 100644
--- a/pw_log/BUILD
+++ b/pw_log/BUILD
@@ -30,6 +30,7 @@
hdrs = [
"public/pw_log/levels.h",
"public/pw_log/log.h",
+ "public/pw_log/options.h",
],
includes = ["public"],
deps = [
diff --git a/pw_log/BUILD.gn b/pw_log/BUILD.gn
index 203739e..cc55db0 100644
--- a/pw_log/BUILD.gn
+++ b/pw_log/BUILD.gn
@@ -33,6 +33,7 @@
public = [
"public/pw_log/levels.h",
"public/pw_log/log.h",
+ "public/pw_log/options.h",
]
}
diff --git a/pw_log/public/pw_log/log.h b/pw_log/public/pw_log/log.h
index ef379ce..2e4dae8 100644
--- a/pw_log/public/pw_log/log.h
+++ b/pw_log/public/pw_log/log.h
@@ -11,21 +11,20 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
-//==============================================================================
-//
+
// This file describes Pigweed's public user-facing logging API.
//
// THIS PUBLIC API IS NOT STABLE OR COMPLETE!
//
// Key functionality is still missing:
//
-// - API for controlling verbosity at compile time
// - API for controlling verbosity at run time
// - API for querying if logging is enabled for the given level or flags
//
#pragma once
#include "pw_log/levels.h"
+#include "pw_log/options.h"
// log_backend.h must ultimately resolve to a header that implements the macros
// required by the logging facade, as described below.
@@ -62,42 +61,6 @@
//
#include "pw_log_backend/log_backend.h"
-// Default: Module name
-// An empty string is used for the module name if it is not set. The
-// PW_LOG_MODULE_NAME_DEFINED macro is set to 1 or 0 to allow pw_log backends to
-// behave differently if the module name is defined. For example, a backend
-// might prefix the format string with PW_LOG_MODULE_NAME ": ", but only if the
-// module name is provided.
-#ifdef PW_LOG_MODULE_NAME
-#define PW_LOG_MODULE_NAME_DEFINED 1
-#else
-#define PW_LOG_MODULE_NAME ""
-#define PW_LOG_MODULE_NAME_DEFINED 0
-#endif // PW_LOG_MODULE_NAME
-
-// Default: Flags
-// For log statements like LOG_INFO that don't have an explicit argument, this
-// is used for the flags value.
-#ifndef PW_LOG_DEFAULT_FLAGS
-#define PW_LOG_DEFAULT_FLAGS 0
-#endif // PW_LOG_DEFAULT_FLAGS
-
-// Default: Log level filtering
-//
-// All log statements have a level, and this define is the default filtering.
-// This is compile-time filtering if the level is a constant.
-#ifndef PW_LOG_LEVEL
-#define PW_LOG_LEVEL PW_LOG_LEVEL_DEBUG
-#endif // PW_LOG_LEVEL
-
-// Default: Log enabled expression
-//
-// This expression determines whether or not the statement is enabled and
-// should be passed to the backend.
-#ifndef PW_LOG_ENABLE_IF
-#define PW_LOG_ENABLE_IF(level, flags) ((level) >= PW_LOG_LEVEL)
-#endif // PW_LOG_ENABLE_IF
-
#ifndef PW_LOG
#define PW_LOG(level, flags, message, ...) \
do { \
diff --git a/pw_log/public/pw_log/options.h b/pw_log/public/pw_log/options.h
new file mode 100644
index 0000000..b0147e3
--- /dev/null
+++ b/pw_log/public/pw_log/options.h
@@ -0,0 +1,68 @@
+// Copyright 2020 The Pigweed Authors
+//
+// 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
+//
+// https://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.
+
+// This file defines macros used to control the behavior of pw_log statements.
+// Files that use pw_log may define these macros BEFORE any headers are
+// #included to customize pw_log.
+//
+//
+// For example, the following sets the log module name to "Foobar" and the
+// minimum log level to WARN:
+//
+// #define PW_LOG_MODULE_NAME "Foobar"
+// #define PW_LOG_LEVEL PW_LOG_LEVEL_WARN
+//
+// #include "foo/bar.h"
+// #include "pw_log/log.h"
+//
+// Users of pw_log should not include this header directly; include
+// "pw_log/log.h" instead. This header is separate from "pw_log/log.h" to avoid
+// circular dependencies when implementing the pw_log facade.
+#pragma once
+
+// Default: Module name
+// An empty string is used for the module name if it is not set. The
+// PW_LOG_MODULE_NAME_DEFINED macro is set to 1 or 0 to allow pw_log backends to
+// behave differently if the module name is defined. For example, a backend
+// might prefix the format string with PW_LOG_MODULE_NAME ": ", but only if the
+// module name is provided.
+#ifdef PW_LOG_MODULE_NAME
+#define PW_LOG_MODULE_NAME_DEFINED 1
+#else
+#define PW_LOG_MODULE_NAME ""
+#define PW_LOG_MODULE_NAME_DEFINED 0
+#endif // PW_LOG_MODULE_NAME
+
+// Default: Flags
+// For log statements like LOG_INFO that don't have an explicit argument, this
+// is used for the flags value.
+#ifndef PW_LOG_DEFAULT_FLAGS
+#define PW_LOG_DEFAULT_FLAGS 0
+#endif // PW_LOG_DEFAULT_FLAGS
+
+// Default: Log level filtering
+//
+// All log statements have a level, and this define is the default filtering.
+// This is compile-time filtering if the level is a constant.
+#ifndef PW_LOG_LEVEL
+#define PW_LOG_LEVEL PW_LOG_LEVEL_DEBUG
+#endif // PW_LOG_LEVEL
+
+// Default: Log enabled expression
+//
+// This expression determines whether or not the statement is enabled and
+// should be passed to the backend.
+#ifndef PW_LOG_ENABLE_IF
+#define PW_LOG_ENABLE_IF(level, flags) ((level) >= PW_LOG_LEVEL)
+#endif // PW_LOG_ENABLE_IF
diff --git a/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h b/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h
index b8fda4d..0bd0c06 100644
--- a/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h
+++ b/pw_log_tokenized/public/pw_log_tokenized/log_tokenized.h
@@ -16,7 +16,7 @@
#include <assert.h>
#include <stdint.h>
-#include "pw_log/log.h"
+#include "pw_log/options.h"
#include "pw_preprocessor/concat.h"
#include "pw_tokenizer/tokenize_to_global_handler_with_payload.h"