Public Member Functions | Protected Member Functions | Static Private Member Functions | Private Attributes | List of all members
spdlog::sinks::android_sink< Mutex > Class Template Referencefinal

#include <android_sink.h>

Inheritance diagram for spdlog::sinks::android_sink< Mutex >:
spdlog::sinks::base_sink< Mutex > spdlog::sinks::sink

Public Member Functions

 android_sink (std::string tag="spdlog", bool use_raw_msg=false)
 
- Public Member Functions inherited from spdlog::sinks::base_sink< Mutex >
 base_sink ()=default
 
 base_sink (const base_sink &)=delete
 
base_sinkoperator= (const base_sink &)=delete
 
void log (const details::log_msg &msg) final
 
void flush () final
 
void set_pattern (const std::string &pattern) final
 
void set_formatter (std::unique_ptr< spdlog::formatter > sink_formatter) final
 
- Public Member Functions inherited from spdlog::sinks::sink
 sink ()
 
 sink (std::unique_ptr< spdlog::pattern_formatter > formatter)
 
virtual ~sink ()=default
 
bool should_log (level::level_enum msg_level) const
 
void set_level (level::level_enum log_level)
 
level::level_enum level () const
 

Protected Member Functions

void sink_it_ (const details::log_msg &msg) override
 
void flush_ () override
 
- Protected Member Functions inherited from spdlog::sinks::base_sink< Mutex >
virtual void set_pattern_ (const std::string &pattern)
 
virtual void set_formatter_ (std::unique_ptr< spdlog::formatter > sink_formatter)
 

Static Private Member Functions

static android_LogPriority convert_to_android_ (spdlog::level::level_enum level)
 

Private Attributes

std::string tag_
 
bool use_raw_msg_
 

Additional Inherited Members

- Protected Attributes inherited from spdlog::sinks::base_sink< Mutex >
Mutex mutex_
 
- Protected Attributes inherited from spdlog::sinks::sink
level_t level_
 
std::unique_ptr< spdlog::formatterformatter_
 

Detailed Description

template<typename Mutex>
class spdlog::sinks::android_sink< Mutex >

Definition at line 34 of file android_sink.h.

Constructor & Destructor Documentation

template<typename Mutex >
spdlog::sinks::android_sink< Mutex >::android_sink ( std::string  tag = "spdlog",
bool  use_raw_msg = false 
)
inlineexplicit

Definition at line 37 of file android_sink.h.

38  : tag_(std::move(tag))
39  , use_raw_msg_(use_raw_msg)
40  {
41  }
def move(depos, offset)
Definition: depos.py:107

Member Function Documentation

template<typename Mutex >
static android_LogPriority spdlog::sinks::android_sink< Mutex >::convert_to_android_ ( spdlog::level::level_enum  level)
inlinestaticprivate

Definition at line 78 of file android_sink.h.

79  {
80  switch (level)
81  {
83  return ANDROID_LOG_VERBOSE;
85  return ANDROID_LOG_DEBUG;
87  return ANDROID_LOG_INFO;
89  return ANDROID_LOG_WARN;
90  case spdlog::level::err:
91  return ANDROID_LOG_ERROR;
93  return ANDROID_LOG_FATAL;
94  default:
95  return ANDROID_LOG_DEFAULT;
96  }
97  }
level::level_enum level() const
Definition: sink.h:45
template<typename Mutex >
void spdlog::sinks::android_sink< Mutex >::flush_ ( )
inlineoverrideprotectedvirtual

Implements spdlog::sinks::base_sink< Mutex >.

Definition at line 75 of file android_sink.h.

75 {}
template<typename Mutex >
void spdlog::sinks::android_sink< Mutex >::sink_it_ ( const details::log_msg msg)
inlineoverrideprotectedvirtual

Implements spdlog::sinks::base_sink< Mutex >.

Definition at line 44 of file android_sink.h.

45  {
46  const android_LogPriority priority = convert_to_android_(msg.level);
47  fmt::memory_buffer formatted;
48  if (use_raw_msg_)
49  {
50  details::fmt_helper::append_string_view(msg.payload, formatted);
51  }
52  else
53  {
54  sink::formatter_->format(msg, formatted);
55  }
56  formatted.push_back('\0');
57  const char *msg_output = formatted.data();
58 
59  // See system/core/liblog/logger_write.c for explanation of return value
60  int ret = __android_log_write(priority, tag_.c_str(), msg_output);
61  int retry_count = 0;
62  while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
63  {
65  ret = __android_log_write(priority, tag_.c_str(), msg_output);
66  retry_count++;
67  }
68 
69  if (ret < 0)
70  {
71  throw spdlog_ex("__android_log_write() failed", ret);
72  }
73  }
basic_memory_buffer< char > memory_buffer
Definition: format.h:553
void msg(const char *fmt,...)
Definition: message.cpp:107
std::unique_ptr< spdlog::formatter > formatter_
Definition: sink.h:55
#define SPDLOG_ANDROID_RETRIES
Definition: android_sink.h:24
void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
Definition: fmt_helper.h:30
static android_LogPriority convert_to_android_(spdlog::level::level_enum level)
Definition: android_sink.h:78
void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT
Definition: os.h:351

Member Data Documentation

template<typename Mutex >
std::string spdlog::sinks::android_sink< Mutex >::tag_
private

Definition at line 99 of file android_sink.h.

template<typename Mutex >
bool spdlog::sinks::android_sink< Mutex >::use_raw_msg_
private

Definition at line 100 of file android_sink.h.


The documentation for this class was generated from the following file: