Skip to content

Commit

Permalink
Write all crit events to cerr (#696)
Browse files Browse the repository at this point in the history
* Write all crit events to cerr

* Make writing almost atomic

* Use global logger
  • Loading branch information
drbasic authored Mar 28, 2024
1 parent 8a3124b commit d3cd2bf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions cloud/blockstore/libs/daemon/common/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void TBootstrapBase::Init()

BootstrapLogging = CreateLoggingService("console", logSettings);
Log = BootstrapLogging->CreateLog("BLOCKSTORE_SERVER");
SetCriticalEventsLog(Log);
Configs->Log = Log;
STORAGE_INFO("NBS server version: " << GetFullVersionString());

Expand Down
3 changes: 2 additions & 1 deletion cloud/filestore/libs/daemon/common/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <cloud/filestore/libs/server/server.h>
#include <cloud/filestore/libs/storage/core/config.h>
#include <cloud/filestore/libs/storage/init/actorsystem.h>

#include <cloud/storage/core/libs/common/scheduler.h>
#include <cloud/storage/core/libs/common/task_queue.h>
#include <cloud/storage/core/libs/common/thread_pool.h>
#include <cloud/storage/core/libs/common/timer.h>
#include <cloud/storage/core/libs/daemon/mlock.h>
#include <cloud/storage/core/libs/diagnostics/cgroup_stats_fetcher.h>
#include <cloud/storage/core/libs/diagnostics/critical_events.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/libs/diagnostics/monitoring.h>
#include <cloud/storage/core/libs/diagnostics/stats_updater.h>
Expand Down Expand Up @@ -99,6 +99,7 @@ TBootstrapCommon::TBootstrapCommon(
BootstrapLogging->Start();

Log = BootstrapLogging->CreateLog(logComponent);
SetCriticalEventsLog(Log);
}

TBootstrapCommon::~TBootstrapCommon()
Expand Down
18 changes: 16 additions & 2 deletions cloud/storage/core/libs/diagnostics/critical_events.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "critical_events.h"

#include "public.h"

#include <library/cpp/logger/log.h>
#include <library/cpp/monlib/dynamic_counters/counters.h>

#include <util/string/builder.h>
Expand All @@ -13,11 +13,17 @@ using namespace NMonitoring;
namespace {

NMonitoring::TDynamicCountersPtr CriticalEvents;
TLog Log;

} // namespace

////////////////////////////////////////////////////////////////////////////////

void SetCriticalEventsLog(TLog log)
{
Log = std::move(log);
}

void InitCriticalEventsCounter(NMonitoring::TDynamicCountersPtr counters)
{
CriticalEvents = std::move(counters);
Expand Down Expand Up @@ -50,7 +56,15 @@ TString ReportCriticalEvent(
fullMessage << "CRITICAL_EVENT:" << sensorName;
if (message) {
fullMessage << ":" << message;
Cerr << fullMessage << Endl;
}

if (Log.IsNotNullLog()) {
Log.AddLog("%s", fullMessage.c_str());
} else {
// Write message and \n in one call. This will reduce the chance of
// shuffling with writings of other threads.
Cerr << fullMessage + '\n';
Cerr.Flush();
}

return fullMessage;
Expand Down
1 change: 1 addition & 0 deletions cloud/storage/core/libs/diagnostics/critical_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace NCloud {

////////////////////////////////////////////////////////////////////////////////

void SetCriticalEventsLog(TLog log);
void InitCriticalEventsCounter(NMonitoring::TDynamicCountersPtr counters);

TString ReportCriticalEvent(
Expand Down

0 comments on commit d3cd2bf

Please sign in to comment.