Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
8178adc6
Unverified
Commit
8178adc6
authored
Sep 14, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: add common functions
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
a8eed52c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
26 deletions
+40
-26
log.c
src/lxc/log.c
+40
-26
No files found.
src/lxc/log.c
View file @
8178adc6
...
...
@@ -101,37 +101,58 @@ static int lxc_log_priority_to_syslog(int priority)
return
LOG_NOTICE
;
}
/*---------------------------------------------------------------------------*/
static
int
log_append_syslog
(
const
struct
lxc_log_appender
*
appender
,
struct
lxc_log_event
*
event
)
static
const
char
*
lxc_log_get_container_name
()
{
#ifndef NO_LXC_CONF
if
(
current_config
&&
!
log_vmname
)
return
current_config
->
name
;
#endif
return
log_vmname
;
}
static
char
*
lxc_log_get_va_msg
(
struct
lxc_log_event
*
event
)
{
char
*
msg
;
int
rc
,
len
;
va_list
args
;
const
char
*
log_container_name
=
log_vmname
;
#ifndef NO_LXC_CONF
if
(
current_config
&&
!
log_container_name
)
log_container_name
=
current_config
->
name
;
#endif
if
(
!
syslog_enable
)
return
0
;
if
(
!
event
)
return
NULL
;
va_copy
(
args
,
*
event
->
vap
);
len
=
vsnprintf
(
NULL
,
0
,
event
->
fmt
,
args
)
+
1
;
va_end
(
args
);
msg
=
malloc
(
len
*
sizeof
(
char
));
if
(
msg
==
NULL
)
return
0
;
if
(
!
msg
)
return
NULL
;
rc
=
vsnprintf
(
msg
,
len
,
event
->
fmt
,
*
event
->
vap
);
if
(
rc
==
-
1
||
rc
>=
len
)
{
free
(
msg
);
return
0
;
return
NULL
;
}
return
msg
;
}
/*---------------------------------------------------------------------------*/
static
int
log_append_syslog
(
const
struct
lxc_log_appender
*
appender
,
struct
lxc_log_event
*
event
)
{
char
*
msg
;
const
char
*
log_container_name
;
if
(
!
syslog_enable
)
return
0
;
log_container_name
=
lxc_log_get_container_name
();
msg
=
lxc_log_get_va_msg
(
event
);
if
(
!
msg
)
return
0
;
syslog
(
lxc_log_priority_to_syslog
(
event
->
priority
),
"%s%s %s - %s:%s:%d - %s"
,
log_container_name
?
log_container_name
:
""
,
...
...
@@ -154,12 +175,7 @@ static int log_append_stderr(const struct lxc_log_appender *appender,
if
(
event
->
priority
<
LXC_LOG_LEVEL_ERROR
)
return
0
;
log_container_name
=
log_vmname
;
#ifndef NO_LXC_CONF
if
(
current_config
&&
!
log_container_name
)
log_container_name
=
current_config
->
name
;
#endif
log_container_name
=
lxc_log_get_container_name
();
fprintf
(
stderr
,
"%s: %s%s"
,
log_prefix
,
log_container_name
?
log_container_name
:
""
,
...
...
@@ -299,18 +315,16 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
int
n
;
ssize_t
ret
;
int
fd_to_use
=
-
1
;
const
char
*
log_container_name
=
log_vmname
;
const
char
*
log_container_name
;
#ifndef NO_LXC_CONF
if
(
current_config
)
{
if
(
current_config
)
if
(
!
lxc_log_use_global_fd
)
fd_to_use
=
current_config
->
logfd
;
if
(
!
log_container_name
)
log_container_name
=
current_config
->
name
;
}
#endif
log_container_name
=
lxc_log_get_container_name
();
if
(
fd_to_use
==
-
1
)
fd_to_use
=
lxc_log_fd
;
...
...
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