pw_log_basic: Make module configurable

Updates pw_log_basic to use the new configuration aproach so projects
can configure log contents.

Change-Id: If7149b5e60d33bed6977b06765f6e1e12222d460
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/23200
Reviewed-by: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Armando Montanez <amontanez@google.com>
This commit is contained in:
Armando Montanez 2020-11-02 15:58:39 -08:00 committed by CQ Bot Account
parent 656fac6f7e
commit f1f4110493
4 changed files with 68 additions and 11 deletions

View File

@ -40,6 +40,7 @@ pw_cc_library(
name = "pw_log_basic",
srcs = [
"log_basic.cc",
"pw_log_basic_private/config.h",
],
deps = [
":headers",

View File

@ -14,9 +14,17 @@
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
declare_args() {
# The build target that overrides the default configuration options for this
# module. This should point to a source set that provides defines through a
# public config (which may -include a file or add defines directly).
pw_log_basic_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
}
config("default_config") {
include_dirs = [ "public" ]
}
@ -41,6 +49,7 @@ pw_source_set("core") {
"$dir_pw_log:facade",
dir_pw_string,
dir_pw_sys_io,
pw_log_basic_CONFIG,
]
public = [ "public/pw_log_basic/log_basic.h" ]
@ -51,7 +60,10 @@ pw_source_set("core") {
defines += [ "PW_EMOJI=1" ]
}
sources = [ "log_basic.cc" ]
sources = [
"log_basic.cc",
"pw_log_basic_private/config.h",
]
}
pw_doc_group("docs") {

View File

@ -19,6 +19,7 @@
#include <cstring>
#include "pw_log/levels.h"
#include "pw_log_basic_private/config.h"
#include "pw_string/string_builder.h"
#include "pw_sys_io/sys_io.h"
@ -37,16 +38,6 @@
#define RESET "\033[0m"
// clang-format on
#ifndef PW_EMOJI
#define PW_EMOJI 0
#endif // PW_EMOJI
// TODO(pwbug/17): Expose these through the config system.
#define PW_LOG_SHOW_FILENAME 0
#define PW_LOG_SHOW_FUNCTION 0
#define PW_LOG_SHOW_FLAG 0
#define PW_LOG_SHOW_MODULE 0
namespace pw::log_basic {
namespace {

View File

@ -0,0 +1,53 @@
// 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.
#pragma once
// Replaces log levels and flag presence indicator with emoji.
#ifndef PW_EMOJI
#define PW_EMOJI 0
#endif // PW_EMOJI
// With all the following flags enabled, log messages look like this:
//
// clang-format off
// my_file.cc : 42 | Foo | TST | INF Hello, world!
// buggy.cc :2145 | ReadBuggyBuffer | * ERR No, BAD!
//
// With emoji:
// my_file.cc : 42 | Foo | TST Hello, world!
// buggy.cc :2145 | ReadBuggyBuffer | 🚩 ❌ No, BAD!
// clang-format on
// Prints the name of the file that emitted the log message.
#ifndef PW_LOG_SHOW_FILENAME
#define PW_LOG_SHOW_FILENAME 0
#endif // PW_LOG_SHOW_FILENAME
// Prints the name of the function that emitted the log message.
#ifndef PW_LOG_SHOW_FUNCTION
#define PW_LOG_SHOW_FUNCTION 0
#endif // PW_LOG_SHOW_FUNCTION
// Prints an indicator for whether or not there are any active flags for a given
// log statement.
#ifndef PW_LOG_SHOW_FLAG
#define PW_LOG_SHOW_FLAG 0
#endif // PW_LOG_SHOW_FLAG
// Prints the module name associated with a log statement. This is provided by
// defining PW_LOG_MODULE_NAME inside module source files, it is not implied by
// module structure or file path magic.
#ifndef PW_LOG_SHOW_MODULE
#define PW_LOG_SHOW_MODULE 0
#endif // PW_LOG_SHOW_MODULE