From a495b97dc886764be083976ca94e51116ed0b34e Mon Sep 17 00:00:00 2001 From: "lambroslambrou@chromium.org" Date: Thu, 19 Jan 2012 03:18:38 +0000 Subject: Refactor system event logging into platform-specific classes. Currently only Linux, as remoting_me2me_host is a Linux-specific GYP target. BUG=109682 TEST=Manual Review URL: http://codereview.chromium.org/9174022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118225 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/host/host_event_logger.cc | 11 +++++++-- remoting/host/host_event_logger.h | 8 ++++++- remoting/host/remoting_me2me_host.cc | 5 +++- remoting/host/system_event_logger.h | 27 +++++++++++++++++++++ remoting/host/system_event_logger_linux.cc | 38 ++++++++++++++++++++++++++++++ remoting/remoting.gyp | 2 ++ 6 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 remoting/host/system_event_logger.h create mode 100644 remoting/host/system_event_logger_linux.cc (limited to 'remoting') diff --git a/remoting/host/host_event_logger.cc b/remoting/host/host_event_logger.cc index f8f6d57..ca8e49a 100644 --- a/remoting/host/host_event_logger.cc +++ b/remoting/host/host_event_logger.cc @@ -13,6 +13,7 @@ #endif // defined(OS_LINUX) #include "remoting/host/chromoting_host.h" +#include "remoting/host/system_event_logger.h" namespace { @@ -27,8 +28,10 @@ void Log(const std::string& message) { namespace remoting { -HostEventLogger::HostEventLogger(ChromotingHost* host) - : host_(host) { +HostEventLogger::HostEventLogger(ChromotingHost* host, + const std::string& application_name) + : host_(host), + system_event_logger_(SystemEventLogger::Create(application_name)) { #if defined(OS_LINUX) openlog("chromoting_host", 0, LOG_USER); #endif @@ -56,4 +59,8 @@ void HostEventLogger::OnAccessDenied(const std::string& jid) { void HostEventLogger::OnShutdown() { } +void HostEventLogger::Log(const std::string& message) { + system_event_logger_->Log(message); +} + } // namespace remoting diff --git a/remoting/host/host_event_logger.h b/remoting/host/host_event_logger.h index 0b849ef..2ca9afc 100644 --- a/remoting/host/host_event_logger.h +++ b/remoting/host/host_event_logger.h @@ -7,17 +7,20 @@ #include +#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "remoting/host/host_status_observer.h" namespace remoting { class ChromotingHost; +class SystemEventLogger; class HostEventLogger : public HostStatusObserver { public: - HostEventLogger(ChromotingHost* host); + HostEventLogger(ChromotingHost* host, const std::string& application_name); virtual ~HostEventLogger(); // HostStatusObserver implementation. These methods will be called from the @@ -28,7 +31,10 @@ class HostEventLogger : public HostStatusObserver { virtual void OnShutdown() OVERRIDE; private: + void Log(const std::string& message); + scoped_refptr host_; + scoped_ptr system_event_logger_; DISALLOW_COPY_AND_ASSIGN(HostEventLogger); }; diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index 1e4c4ae..6cb5565 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -40,6 +40,9 @@ namespace { +// This is used for tagging system event logs. +const char kApplicationName[] = "remoting_me2me_host"; + // These are used for parsing the config-file locations from the command line, // and for defining the default locations if the switches are not present. const char kAuthConfigSwitchName[] = "auth-config"; @@ -174,7 +177,7 @@ class HostProcess { new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); log_to_server_.reset(new LogToServer(host_, signal_strategy_.get())); - host_event_logger_.reset(new HostEventLogger(host_)); + host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); host_->Start(); diff --git a/remoting/host/system_event_logger.h b/remoting/host/system_event_logger.h new file mode 100644 index 0000000..ee894ee --- /dev/null +++ b/remoting/host/system_event_logger.h @@ -0,0 +1,27 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_HOST_SYSTEM_EVENT_LOGGER_H_ +#define REMOTING_HOST_SYSTEM_EVENT_LOGGER_H_ + +#include + +#include "base/memory/scoped_ptr.h" + +namespace remoting { + +class SystemEventLogger { + public: + virtual ~SystemEventLogger() {} + + virtual void Log(const std::string& message) = 0; + + // Create an event-logger that tags log messages with |application_name|. + static scoped_ptr Create( + const std::string& application_name); +}; + +} // namespace remoting + +#endif // REMOTING_HOST_SYSTEM_EVENT_LOGGER_H_ diff --git a/remoting/host/system_event_logger_linux.cc b/remoting/host/system_event_logger_linux.cc new file mode 100644 index 0000000..4518d5d --- /dev/null +++ b/remoting/host/system_event_logger_linux.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/host/system_event_logger.h" + +#include + +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +namespace remoting { + +namespace { + +class SystemEventLoggerLinux : public SystemEventLogger { + public: + SystemEventLoggerLinux(const std::string& application_name) { + openlog(application_name.c_str(), 0, LOG_USER); + } + + virtual void Log(const std::string& message) OVERRIDE { + syslog(LOG_USER | LOG_NOTICE, "%s", message.c_str()); + } + + DISALLOW_COPY_AND_ASSIGN(SystemEventLoggerLinux); +}; + +} // namespace + +// static +scoped_ptr SystemEventLogger::Create( + const std::string& application_name) { + return scoped_ptr( + new SystemEventLoggerLinux(application_name)); +} + +} // namespace remoting diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index b3d9694..d1991b8 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -220,6 +220,8 @@ 'host/host_event_logger.cc', 'host/host_event_logger.h', 'host/remoting_me2me_host.cc', + 'host/system_event_logger_linux.cc', + 'host/system_event_logger.h', ], }, # end of target 'remoting_me2me_host' -- cgit v1.1