Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
bf02f574
Commit
bf02f574
authored
Sep 14, 2016
by
Hugh Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Android sink.
1. Remove lock. 2. Improve error detection. 3. Remove unsupported log levels.
parent
f2c96924
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
34 deletions
+16
-34
android_sink.h
include/spdlog/sinks/android_sink.h
+16
-34
No files found.
include/spdlog/sinks/android_sink.h
View file @
bf02f574
...
...
@@ -7,51 +7,42 @@
#if defined(__ANDROID__)
#include <spdlog/sinks/base_sink.h>
#include <spdlog/details/null_mutex.h>
#include <android/log.h>
#include <spdlog/sinks/sink.h>
#include <mutex>
#include <string>
#include <android/log.h>
namespace
spdlog
{
namespace
sinks
{
/*
* Android sink (logging using __android_log_write)
* __android_log_write is thread-safe. No lock is needed.
*/
template
<
class
Mutex
>
class
base_android_sink
:
public
base_sink
<
Mutex
>
class
android_sink
:
public
sink
{
public
:
explicit
base_android_sink
(
std
::
string
tag
=
"spdlog"
)
:
_tag
(
tag
)
{
}
explicit
android_sink
(
const
std
::
string
&
tag
=
"spdlog"
)
:
_tag
(
tag
)
{}
void
flush
()
override
{
}
protected
:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
void
log
(
const
details
::
log_msg
&
msg
)
override
{
const
android_LogPriority
priority
=
convert_to_android
(
msg
.
level
);
const
int
expected_size
=
msg
.
formatted
.
size
();
const
int
size
=
__android_log_write
(
// See system/core/liblog/logger_write.c for explanation of return value
const
int
ret
=
__android_log_write
(
priority
,
_tag
.
c_str
(),
msg
.
formatted
.
c_str
()
);
if
(
size
>
expected_size
)
{
// Will write a little bit more than original message
}
else
{
throw
spdlog_ex
(
"Send to Android logcat failed"
);
if
(
ret
<
0
)
{
throw
spdlog_ex
(
"__android_log_write() failed"
,
ret
);
}
}
void
flush
()
override
{
}
private
:
static
android_LogPriority
convert_to_android
(
spdlog
::
level
::
level_enum
level
)
{
...
...
@@ -63,29 +54,20 @@ private:
return
ANDROID_LOG_DEBUG
;
case
spdlog
:
:
level
::
info
:
return
ANDROID_LOG_INFO
;
case
spdlog
:
:
level
::
notice
:
return
ANDROID_LOG_INFO
;
case
spdlog
:
:
level
::
warn
:
return
ANDROID_LOG_WARN
;
case
spdlog
:
:
level
::
err
:
return
ANDROID_LOG_ERROR
;
case
spdlog
:
:
level
::
critical
:
return
ANDROID_LOG_FATAL
;
case
spdlog
:
:
level
::
alert
:
return
ANDROID_LOG_FATAL
;
case
spdlog
:
:
level
::
emerg
:
return
ANDROID_LOG_FATAL
;
default
:
throw
spdlog_ex
(
"Incorrect level value"
)
;
return
ANDROID_LOG_DEFAULT
;
}
}
std
::
string
_tag
;
};
typedef
base_android_sink
<
std
::
mutex
>
android_sink_mt
;
typedef
base_android_sink
<
details
::
null_mutex
>
android_sink_st
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment