forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chip_logging_backend option and 'none' and 'syslog' backends (pro…
…ject-chip#34830) * Tidy up stdio logging target dependencies Also rename from Logging.cpp to Stdio.cpp and add license header. * Add chip_logging_backend option and 'none' backend chip_logging_backend controls which backend is pulled in by the src/platform/logging:default target. The default is 'platform', retaining the current behavior. On Darwin, remove the no-op LoggingImpl and make stdio the default backend when compiling tools or example apps. Use the new 'none' backend when building Matter.framework, retaining current behavior. Depend on logging:default instead of logging:stdio for linux:app-main examples. * Add a syslog logging backend * Fix STM32 build * Use stdio logging backend for cirque tests The stdio and linux backends use slightly different output formats and the cirque tests currently only parse the stdio format correctly. * Apply suggestions from code review Co-authored-by: Boris Zbarsky <[email protected]> * Fix stray space in GN string comparison --------- Co-authored-by: Boris Zbarsky <[email protected]>
- Loading branch information
1 parent
9efb599
commit e0a765b
Showing
11 changed files
with
148 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,6 @@ static_library("logging") { | |
sources = [ | ||
"Logging.h", | ||
"Logging.mm", | ||
"LoggingImpl.cpp", | ||
] | ||
|
||
deps = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
src/platform/logging/impl/stdio/Logging.cpp → src/platform/logging/impl/Stdio.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP 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 | ||
* | ||
* 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 <platform/logging/LogV.h> | ||
|
||
#include <lib/core/CHIPConfig.h> | ||
#include <lib/support/logging/Constants.h> | ||
|
||
#include <mutex> | ||
#include <syslog.h> | ||
|
||
namespace chip { | ||
namespace Logging { | ||
namespace Platform { | ||
|
||
namespace { | ||
int LogPriority(uint8_t category) | ||
{ | ||
switch (category) | ||
{ | ||
case kLogCategory_Error: | ||
return LOG_ERR; | ||
case kLogCategory_Progress: | ||
return LOG_NOTICE; | ||
default: | ||
return LOG_DEBUG; | ||
} | ||
} | ||
} // namespace | ||
|
||
void LogV(const char * module, uint8_t category, const char * msg, va_list v) | ||
{ | ||
static std::mutex sMutex; | ||
static bool sInitialized = false; | ||
static char sBuffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE]; | ||
std::lock_guard guard(sMutex); | ||
|
||
if (!sInitialized) | ||
{ | ||
openlog(nullptr, 0, LOG_DAEMON); | ||
sInitialized = true; | ||
} | ||
|
||
// Pre-format the message so we can include the module name | ||
vsnprintf(sBuffer, sizeof(sBuffer), msg, v); | ||
syslog(LogPriority(category), "%s: %s", module, sBuffer); | ||
} | ||
|
||
} // namespace Platform | ||
} // namespace Logging | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters