Skip to content

Commit

Permalink
Syslog and logging tweaks (project-chip#34941)
Browse files Browse the repository at this point in the history
* Make syslog ident and facility overridable and tweak options

* Linux: Be a little less verbose when writing settings
  • Loading branch information
ksperling-apple authored and PeterC1965 committed Aug 28, 2024
1 parent 6cf254e commit ca95292
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/platform/Linux/CHIPLinuxStorageIni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ CHIP_ERROR ChipLinuxStorageIni::CommitConfig(const std::string & configFile)
if (fd != -1)
{
std::ofstream ofs;

ChipLogProgress(DeviceLayer, "writing settings to file (%s)", tmpPath.c_str());

ofs.open(tmpPath, std::ofstream::out | std::ofstream::trunc);
mConfigStore.generate(ofs);

close(fd);

if (rename(tmpPath.c_str(), configFile.c_str()) == 0)
{
ChipLogProgress(DeviceLayer, "renamed tmp file to file (%s)", configFile.c_str());
ChipLogDetail(DeviceLayer, "wrote settings to %s", configFile.c_str());
}
else
{
Expand Down
10 changes: 9 additions & 1 deletion src/platform/logging/impl/Syslog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
#include <mutex>
#include <syslog.h>

#ifndef CHIP_SYSLOG_IDENT
#define CHIP_SYSLOG_IDENT nullptr
#endif

#ifndef CHIP_SYSLOG_FACILITY
#define CHIP_SYSLOG_FACILITY LOG_DAEMON
#endif

namespace chip {
namespace Logging {
namespace Platform {
Expand Down Expand Up @@ -51,7 +59,7 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v)

if (!sInitialized)
{
openlog(nullptr, 0, LOG_DAEMON);
openlog(CHIP_SYSLOG_IDENT, LOG_CONS | LOG_PID, CHIP_SYSLOG_FACILITY);
sInitialized = true;
}

Expand Down

0 comments on commit ca95292

Please sign in to comment.