- Android log channel implementation

- Removes warning from Bugcheck.h on Android

fixes #122
This commit is contained in:
Rangel Reale 2015-01-29 11:14:39 -02:00
parent 120cbdc64a
commit 1c648764c2
5 changed files with 127 additions and 1 deletions

View File

@ -16,6 +16,9 @@ POCO_HEADERS_AUTO( SRCS include/Poco/OpcomChannel.h )
POCO_SOURCES_AUTO_PLAT( SRCS UNIX src/SyslogChannel.cpp )
POCO_HEADERS_AUTO( SRCS include/Poco/SyslogChannel.h )
POCO_SOURCES_AUTO_PLAT( SRCS ANDROID src/AndroidLogChannel.cpp )
POCO_HEADERS_AUTO( SRCS include/Poco/AndroidLogChannel.h )
# For Windows CE we need to disable these
if(WINCE)
POCO_SOURCES_AUTO_PLAT( SRCS OFF

View File

@ -56,6 +56,10 @@ else
objects += SyslogChannel
endif
ifeq ($(findstring Android, $(POCO_CONFIG)), Android)
objects += AndroidLogChannel
endif
target = PocoFoundation
target_version = $(LIBVERSION)
target_libs =

View File

@ -0,0 +1,54 @@
//
// AndroidLogChannel.h
//
// $Id: //poco/1.4/Foundation/include/Poco/AndroidLogChannel.h#2 $
//
// Library: Foundation
// Package: Logging
// Module: AndroidLogChannel
//
// Definition of the AndroidLogChannel class.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Foundation_AndroidLogChannel_INCLUDED
#define Foundation_AndroidLogChannel_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/Channel.h"
namespace Poco {
class AndroidLogChannel: public Poco::Channel
/// A channel that writes to the Android log subsystem.
///
/// Only the message's text is written, followed
/// by a newline, using the tag passed on the constructor.
{
public:
AndroidLogChannel(const std::string &tag);
/// Creates the AndroidLogChannel.
void log(const Message& msg);
/// Logs the given message to the channel's stream.
protected:
~AndroidLogChannel();
private:
std::string _tag;
};
} // namespace Poco
#endif // Foundation_AndroidLogChannel_INCLUDED

View File

@ -148,7 +148,7 @@ protected:
//
#if defined(POCO_COMPILER_GCC) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)
#if defined(POCO_COMPILER_GCC) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) && !defined(POCO_ANDROID)
GCC_DIAG_OFF(unused-local-typedefs) // supress numerous gcc warnings
#endif // POCO_COMPILER_GCC && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)

View File

@ -0,0 +1,65 @@
//
// AndroidLogChannel.cpp
//
// $Id: //poco/1.4/Foundation/src/AndroidLogChannel.cpp#2 $
//
// Library: Foundation
// Package: Logging
// Module: AndroidLogChannel
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/AndroidLogChannel.h"
#include "Poco/Message.h"
#include <android/log.h>
namespace Poco {
AndroidLogChannel::AndroidLogChannel(const std::string &tag) :
_tag(tag)
{
}
AndroidLogChannel::~AndroidLogChannel()
{
}
void AndroidLogChannel::log(const Message& msg)
{
int prio = ANDROID_LOG_DEBUG;
switch (msg.getPriority())
{
case Message::PRIO_FATAL:
prio = ANDROID_LOG_FATAL;
break;
case Message::PRIO_CRITICAL:
case Message::PRIO_ERROR:
prio = ANDROID_LOG_ERROR;
break;
case Message::PRIO_WARNING:
prio = ANDROID_LOG_WARN;
break;
case Message::PRIO_NOTICE:
case Message::PRIO_INFORMATION:
prio = ANDROID_LOG_INFO;
break;
case Message::PRIO_TRACE:
prio = ANDROID_LOG_VERBOSE;
break;
}
__android_log_print(prio, _tag.c_str(), msg.getText().c_str());
}
} // namespace Poco