Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d7df5e1c
Commit
d7df5e1c
authored
Jun 23, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LogBackend: pass std::string_view to Log()
parent
e4e4576a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
12 deletions
+13
-12
Log.hxx
src/Log.hxx
+2
-1
LogBackend.cxx
src/LogBackend.cxx
+11
-11
No files found.
src/Log.hxx
View file @
d7df5e1c
...
@@ -24,11 +24,12 @@
...
@@ -24,11 +24,12 @@
#include "util/Compiler.h"
#include "util/Compiler.h"
#include <exception>
#include <exception>
#include <string_view>
class
Domain
;
class
Domain
;
void
void
Log
(
LogLevel
level
,
const
Domain
&
domain
,
const
char
*
msg
)
noexcept
;
Log
(
LogLevel
level
,
const
Domain
&
domain
,
std
::
string_view
msg
)
noexcept
;
gcc_printf
(
3
,
4
)
gcc_printf
(
3
,
4
)
void
void
...
...
src/LogBackend.cxx
View file @
d7df5e1c
...
@@ -103,10 +103,9 @@ log_date() noexcept
...
@@ -103,10 +103,9 @@ log_date() noexcept
* characters.
* characters.
*/
*/
static
int
static
int
chomp_length
(
const
char
*
p
)
noexcept
chomp_length
(
std
::
string_view
p
)
noexcept
{
{
size_t
length
=
strlen
(
p
);
return
StripRight
(
p
.
data
(),
p
.
size
());
return
StripRight
(
p
,
length
);
}
}
#ifdef HAVE_SYSLOG
#ifdef HAVE_SYSLOG
...
@@ -137,11 +136,11 @@ ToSysLogLevel(LogLevel log_level) noexcept
...
@@ -137,11 +136,11 @@ ToSysLogLevel(LogLevel log_level) noexcept
}
}
static
void
static
void
SysLog
(
const
Domain
&
domain
,
LogLevel
log_level
,
const
char
*
message
)
noexcept
SysLog
(
const
Domain
&
domain
,
LogLevel
log_level
,
std
::
string_view
message
)
noexcept
{
{
syslog
(
ToSysLogLevel
(
log_level
),
"%s: %.*s"
,
syslog
(
ToSysLogLevel
(
log_level
),
"%s: %.*s"
,
domain
.
GetName
(),
domain
.
GetName
(),
chomp_length
(
message
),
message
);
chomp_length
(
message
),
message
.
data
()
);
}
}
void
void
...
@@ -161,12 +160,12 @@ LogFinishSysLog() noexcept
...
@@ -161,12 +160,12 @@ LogFinishSysLog() noexcept
#endif
#endif
static
void
static
void
FileLog
(
const
Domain
&
domain
,
const
char
*
message
)
noexcept
FileLog
(
const
Domain
&
domain
,
std
::
string_view
message
)
noexcept
{
{
fprintf
(
stderr
,
"%s%s: %.*s
\n
"
,
fprintf
(
stderr
,
"%s%s: %.*s
\n
"
,
enable_timestamp
?
log_date
()
:
""
,
enable_timestamp
?
log_date
()
:
""
,
domain
.
GetName
(),
domain
.
GetName
(),
chomp_length
(
message
),
message
);
chomp_length
(
message
),
message
.
data
()
);
#ifdef _WIN32
#ifdef _WIN32
/* force-flush the log file, because setvbuf() does not seem
/* force-flush the log file, because setvbuf() does not seem
...
@@ -178,15 +177,16 @@ FileLog(const Domain &domain, const char *message) noexcept
...
@@ -178,15 +177,16 @@ FileLog(const Domain &domain, const char *message) noexcept
#endif
/* !ANDROID */
#endif
/* !ANDROID */
void
void
Log
(
LogLevel
level
,
const
Domain
&
domain
,
const
char
*
msg
)
noexcept
Log
(
LogLevel
level
,
const
Domain
&
domain
,
std
::
string_view
msg
)
noexcept
{
{
#ifdef ANDROID
#ifdef ANDROID
__android_log_print
(
ToAndroidLogLevel
(
level
),
"MPD"
,
__android_log_print
(
ToAndroidLogLevel
(
level
),
"MPD"
,
"%s: %s"
,
domain
.
GetName
(),
msg
);
"%s: %.*s"
,
domain
.
GetName
(),
(
int
)
msg
.
size
(),
msg
.
data
());
if
(
logListener
!=
nullptr
)
{
if
(
logListener
!=
nullptr
)
{
char
buffer
[
1024
];
char
buffer
[
1024
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"%s: %s"
,
snprintf
(
buffer
,
sizeof
(
buffer
),
"%s: %
.*
s"
,
domain
.
GetName
(),
msg
);
domain
.
GetName
(),
(
int
)
msg
.
size
(),
msg
.
data
()
);
logListener
->
OnLog
(
Java
::
GetEnv
(),
ToAndroidLogLevel
(
level
),
logListener
->
OnLog
(
Java
::
GetEnv
(),
ToAndroidLogLevel
(
level
),
buffer
);
buffer
);
...
...
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