pull/50/merge
Francois Coulombe 11 years ago
commit 7726ffa6f5

@ -141,7 +141,9 @@ FMT_FUNC int safe_strerror(
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT(true) {
assert(buffer != 0 && buffer_size != 0);
int result = 0;
#ifdef _GNU_SOURCE
#ifdef __ANDROID__
result = strerror_r(error_code, buffer, buffer_size);
#elif defined(_GNU_SOURCE)
char *message = strerror_r(error_code, buffer, buffer_size);
// If the buffer is full then the message is probably truncated.
if (message == buffer && strlen(buffer) == buffer_size - 1)
@ -1165,4 +1167,4 @@ template int spdlog::details::fmt::internal::CharTraits<wchar_t>::format_float(
#if _MSC_VER
# pragma warning(pop)
#endif
#endif

@ -0,0 +1,77 @@
/*************************************************************************/
/* spdlog - an extremely fast and easy to use c++11 logging library. */
/* Copyright (c) 2015 Francois Coulombe. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#pragma once
#ifdef __ANDROID__
#include <ostream>
#include <mutex>
#include <memory>
#include <android/log.h>
#include "../details/null_mutex.h"
#include "./base_sink.h"
namespace spdlog
{
namespace sinks
{
template<class Mutex>
class android_sink: public base_sink<Mutex>
{
public:
explicit android_sink(std::ostream& /*os*/, bool force_flush=false)
://_ostream(os),
_force_flush(force_flush) {}
android_sink(const android_sink&) = delete;
android_sink& operator=(const android_sink&) = delete;
virtual ~android_sink() = default;
protected:
virtual void _sink_it(const details::log_msg& msg) override
{
constexpr int LoveLevelMapping[] =
{
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_FATAL,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT,
};
((void)__android_log_print(LoveLevelMapping[msg.level], msg.logger_name.c_str(), msg.formatted.data()));
}
//std::ostream& _ostream;
bool _force_flush;
};
typedef android_sink<std::mutex> android_sink_mt;
typedef android_sink<details::null_mutex> android_sink_st;
}
}
#endif

@ -26,6 +26,8 @@
#include <iostream>
#include <mutex>
#include "./android_sink.h"
#include "./ostream_sink.h"
#include "../details/null_mutex.h"
@ -35,10 +37,16 @@ namespace sinks
{
template <class Mutex>
class stdout_sink : public ostream_sink<Mutex>
#ifdef __ANDROID__
# define outstream_sink android_sink
#else
# define outstream_sink ostream_sink
#endif
class stdout_sink : public outstream_sink<Mutex>
{
public:
stdout_sink() : ostream_sink<Mutex>(std::cout, true) {}
stdout_sink() : outstream_sink<Mutex>(std::cout, true) {}
};
@ -47,10 +55,10 @@ typedef stdout_sink<std::mutex> stdout_sink_mt;
template <class Mutex>
class stderr_sink : public ostream_sink<Mutex>
class stderr_sink : public outstream_sink<Mutex>
{
public:
stderr_sink() : ostream_sink<Mutex>(std::cerr, true) {}
stderr_sink() : outstream_sink<Mutex>(std::cerr, true) {}
};
typedef stderr_sink<std::mutex> stderr_sink_mt;

Loading…
Cancel
Save