| // Copyright 2021 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include <lib/syslog/cpp/macros.h> |
| |
| #include <Weave/Support/logging/WeaveLogging.h> |
| |
| #if WEAVE_LOGGING_STYLE_EXTERNAL |
| using namespace ::nl::Weave; |
| |
| namespace nl { |
| namespace Weave { |
| namespace Logging { |
| namespace { |
| constexpr size_t kFormattedMessageSize = 256; |
| } // namespace |
| |
| void Log(uint8_t module, uint8_t category, const char * file, uint32_t line, const char * msg, |
| va_list v) |
| { |
| if (IsCategoryEnabled(category)) |
| { |
| char formattedMsg[kFormattedMessageSize]; |
| vsnprintf(formattedMsg, sizeof(formattedMsg), msg, v); |
| |
| char module_name[nlWeaveLoggingModuleNameLen + 1]; |
| GetModuleName(module_name, module); |
| |
| syslog::LogSeverity severity = syslog::LOG_INFO; |
| switch (category) |
| { |
| case kLogCategory_Error: |
| severity = syslog::LOG_ERROR; |
| break; |
| case kLogCategory_Progress: |
| case kLogCategory_Retain: |
| case kLogCategory_Detail: |
| severity = syslog::LOG_INFO; |
| break; |
| } |
| |
| const char * file_basename = strrchr(file, '/'); |
| file_basename = file_basename ? file_basename + 1 : file; |
| syslog::LogMessage(severity, file_basename, line, nullptr, nullptr).stream() |
| << "[" << module_name << "] " << formattedMsg; |
| } |
| } |
| |
| void Log(uint8_t module, uint8_t category, const char * msg, ...) |
| { |
| va_list vargs; |
| va_start(vargs, msg); |
| Log(module, category, "", 0, msg, vargs); |
| va_end(vargs); |
| } |
| |
| void Log(uint8_t module, uint8_t category, const char * file, uint32_t line, const char * msg, ...) |
| { |
| va_list vargs; |
| va_start(vargs, msg); |
| Log(module, category, file, line, msg, vargs); |
| va_end(vargs); |
| } |
| |
| } // namespace Logging |
| } // namespace Weave |
| } // namespace nl |
| |
| #endif // WEAVE_LOGGING_STYLE_EXTERNAL |