osquery-1/osquery/logger/logger.cpp
mike@arpaia.co b9f732c31f Updating the license comment to be the correct open source header
As per t5494224, all of the license headers in osquery needed to be updated
to reflect the correct open source header style.
2014-12-18 10:52:55 -08:00

71 lines
2.0 KiB
C++

/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <algorithm>
#include <thread>
#include <glog/logging.h>
#include <osquery/flags.h>
#include <osquery/logger.h>
#include <osquery/logger/plugin.h>
using osquery::Status;
namespace osquery {
/// `log_receiver` defines the default log receiver plugin name.
DEFINE_osquery_flag(string,
log_receiver,
"filesystem",
"The upstream log receiver to log messages to.");
DEFINE_osquery_flag(bool,
log_result_events,
true,
"Log scheduled results as events.");
Status logString(const std::string& s) {
return logString(s, FLAGS_log_receiver);
}
Status logString(const std::string& s, const std::string& receiver) {
if (REGISTERED_LOGGER_PLUGINS.find(receiver) ==
REGISTERED_LOGGER_PLUGINS.end()) {
LOG(ERROR) << "Logger receiver " << receiver << " not found";
return Status(1, "Logger receiver not found");
}
auto log_status = REGISTERED_LOGGER_PLUGINS.at(receiver)->logString(s);
if (!log_status.ok()) {
return log_status;
}
return Status(0, "OK");
}
Status logScheduledQueryLogItem(const osquery::ScheduledQueryLogItem& results) {
return logScheduledQueryLogItem(results, FLAGS_log_receiver);
}
Status logScheduledQueryLogItem(const osquery::ScheduledQueryLogItem& results,
const std::string& receiver) {
std::string json;
Status status;
if (FLAGS_log_result_events) {
status = serializeScheduledQueryLogItemAsEventsJSON(results, json);
} else {
status = serializeScheduledQueryLogItemJSON(results, json);
}
if (!status.ok()) {
return status;
}
return logString(json, receiver);
}
}