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
a5348a37
Commit
a5348a37
authored
Nov 05, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: use GLib message logging
The logging functions from log.h are deprecated, and the code should use GLib logging instead. Make ERROR(), WARNING() etc. call g_logv() internally.
parent
a05fa5cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
24 deletions
+15
-24
log.c
src/log.c
+15
-20
log.h
src/log.h
+0
-4
No files found.
src/log.c
View file @
a5348a37
...
@@ -33,10 +33,12 @@
...
@@ -33,10 +33,12 @@
#include <pthread.h>
#include <pthread.h>
#include <glib.h>
#include <glib.h>
#define LOG_LEVEL_SECURE G_LOG_LEVEL_MESSAGE
#define LOG_DATE_BUF_SIZE 16
#define LOG_DATE_BUF_SIZE 16
#define LOG_DATE_LEN (LOG_DATE_BUF_SIZE - 1)
#define LOG_DATE_LEN (LOG_DATE_BUF_SIZE - 1)
static
unsigned
int
log_threshold
=
LOG_LEVEL_LOW
;
static
unsigned
int
log_threshold
=
G_LOG_LEVEL_INFO
;
static
int
stdout_mode
=
1
;
static
int
stdout_mode
=
1
;
static
int
out_fd
=
-
1
;
static
int
out_fd
=
-
1
;
...
@@ -62,13 +64,6 @@ static const char *log_date(void)
...
@@ -62,13 +64,6 @@ static const char *log_date(void)
return
buf
;
return
buf
;
}
}
static
void
do_log
(
FILE
*
fp
,
const
char
*
fmt
,
va_list
args
)
{
if
(
!
stdout_mode
)
fwrite
(
log_date
(),
LOG_DATE_LEN
,
1
,
fp
);
vfprintf
(
fp
,
fmt
,
args
);
}
void
initLog
(
const
int
verbose
)
void
initLog
(
const
int
verbose
)
{
{
ConfigParam
*
param
;
ConfigParam
*
param
;
...
@@ -77,17 +72,17 @@ void initLog(const int verbose)
...
@@ -77,17 +72,17 @@ void initLog(const int verbose)
setvbuf
(
stdout
,
(
char
*
)
NULL
,
_IONBF
,
0
);
setvbuf
(
stdout
,
(
char
*
)
NULL
,
_IONBF
,
0
);
if
(
verbose
)
{
if
(
verbose
)
{
log_threshold
=
LOG_LEVEL_DEBUG
;
log_threshold
=
G_
LOG_LEVEL_DEBUG
;
return
;
return
;
}
}
if
(
!
(
param
=
getConfigParam
(
CONF_LOG_LEVEL
)))
if
(
!
(
param
=
getConfigParam
(
CONF_LOG_LEVEL
)))
return
;
return
;
if
(
0
==
strcmp
(
param
->
value
,
"default"
))
{
if
(
0
==
strcmp
(
param
->
value
,
"default"
))
{
log_threshold
=
LOG_LEVEL_LOW
;
log_threshold
=
G_LOG_LEVEL_INFO
;
}
else
if
(
0
==
strcmp
(
param
->
value
,
"secure"
))
{
}
else
if
(
0
==
strcmp
(
param
->
value
,
"secure"
))
{
log_threshold
=
LOG_LEVEL_SECURE
;
log_threshold
=
LOG_LEVEL_SECURE
;
}
else
if
(
0
==
strcmp
(
param
->
value
,
"verbose"
))
{
}
else
if
(
0
==
strcmp
(
param
->
value
,
"verbose"
))
{
log_threshold
=
LOG_LEVEL_DEBUG
;
log_threshold
=
G_
LOG_LEVEL_DEBUG
;
}
else
{
}
else
{
FATAL
(
"unknown log level
\"
%s
\"
at line %i
\n
"
,
FATAL
(
"unknown log level
\"
%s
\"
at line %i
\n
"
,
param
->
value
,
param
->
line
);
param
->
value
,
param
->
line
);
...
@@ -129,22 +124,22 @@ void setup_log_output(const int use_stdout)
...
@@ -129,22 +124,22 @@ void setup_log_output(const int use_stdout)
}
}
}
}
#define log_func(func,level
,fp
) \
#define log_func(func,level) \
mpd_printf void func(const char *fmt, ...) \
mpd_printf void func(const char *fmt, ...) \
{ \
{ \
if ((int)log_threshold
>
= level) { \
if ((int)log_threshold
<
= level) { \
va_list args; \
va_list args; \
va_start(args, fmt); \
va_start(args, fmt); \
do_log(fp, fmt, args);
\
g_logv(NULL, level, fmt, args);
\
va_end(args); \
va_end(args); \
} \
} \
}
}
log_func
(
ERROR
,
0
,
stderr
)
log_func
(
ERROR
,
G_LOG_LEVEL_WARNING
)
log_func
(
WARNING
,
0
,
stderr
)
log_func
(
WARNING
,
G_LOG_LEVEL_WARNING
)
log_func
(
LOG
,
0
,
stdout
)
log_func
(
LOG
,
G_LOG_LEVEL_MESSAGE
)
log_func
(
SECURE
,
LOG_LEVEL_SECURE
,
stdout
)
log_func
(
SECURE
,
LOG_LEVEL_SECURE
)
log_func
(
DEBUG
,
LOG_LEVEL_DEBUG
,
stdout
)
log_func
(
DEBUG
,
G_LOG_LEVEL_DEBUG
)
#undef log_func
#undef log_func
...
@@ -152,7 +147,7 @@ mpd_printf mpd_noreturn void FATAL(const char *fmt, ...)
...
@@ -152,7 +147,7 @@ mpd_printf mpd_noreturn void FATAL(const char *fmt, ...)
{
{
va_list
args
;
va_list
args
;
va_start
(
args
,
fmt
);
va_start
(
args
,
fmt
);
do_log
(
stderr
,
fmt
,
args
);
g_logv
(
NULL
,
G_LOG_LEVEL_ERROR
,
fmt
,
args
);
va_end
(
args
);
va_end
(
args
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
...
src/log.h
View file @
a5348a37
...
@@ -21,10 +21,6 @@
...
@@ -21,10 +21,6 @@
#include "gcc.h"
#include "gcc.h"
#define LOG_LEVEL_LOW 0
#define LOG_LEVEL_SECURE 1
#define LOG_LEVEL_DEBUG 2
mpd_printf
void
ERROR
(
const
char
*
fmt
,
...);
mpd_printf
void
ERROR
(
const
char
*
fmt
,
...);
mpd_printf
void
LOG
(
const
char
*
fmt
,
...);
mpd_printf
void
LOG
(
const
char
*
fmt
,
...);
mpd_printf
void
SECURE
(
const
char
*
fmt
,
...);
mpd_printf
void
SECURE
(
const
char
*
fmt
,
...);
...
...
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