#include "base/syslog_logging.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <sddl.h>
#include "base/debug/stack_trace.h"
#include "base/strings/string_util.h"
#include "base/win/scoped_handle.h"
#include "base/win/win_util.h"
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include <syslog.h>
#undef LOG_INFO
#undef LOG_WARNING
#endif
#include <ostream>
#include <string>
namespace logging {
namespace {
bool g_logging_enabled = …;
}
#if BUILDFLAG(IS_WIN)
namespace {
std::string* g_event_source_name = nullptr;
uint16_t g_category = 0;
uint32_t g_event_id = 0;
std::wstring* g_user_sid = nullptr;
class EventLogHandleTraits {
public:
using Handle = HANDLE;
EventLogHandleTraits() = delete;
EventLogHandleTraits(const EventLogHandleTraits&) = delete;
EventLogHandleTraits& operator=(const EventLogHandleTraits&) = delete;
static bool CloseHandle(HANDLE handle) {
return ::DeregisterEventSource(handle) != FALSE;
}
static bool IsHandleValid(HANDLE handle) { return handle != nullptr; }
static HANDLE NullHandle() { return nullptr; }
};
using ScopedEventLogHandle =
base::win::GenericScopedHandle<EventLogHandleTraits,
base::win::DummyVerifierTraits>;
}
void SetEventSource(const std::string& name,
uint16_t category,
uint32_t event_id) {
DCHECK_EQ(nullptr, g_event_source_name);
g_event_source_name = new std::string(name);
g_category = category;
g_event_id = event_id;
DCHECK_EQ(nullptr, g_user_sid);
g_user_sid = new std::wstring();
base::win::GetUserSidString(g_user_sid);
}
void ResetEventSourceForTesting() {
delete g_event_source_name;
g_event_source_name = nullptr;
delete g_user_sid;
g_user_sid = nullptr;
}
#endif
EventLogMessage::EventLogMessage(const char* file,
int line,
LogSeverity severity)
: … { … }
EventLogMessage::~EventLogMessage() { … }
void SetSyslogLoggingForTesting(bool logging_enabled) { … }
}