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
9990e847
Commit
9990e847
authored
Nov 02, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LogInit: migrate from class Error to C++ exceptions
parent
d765182b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
31 deletions
+24
-31
LogInit.cxx
src/LogInit.cxx
+18
-23
LogInit.hxx
src/LogInit.hxx
+5
-4
Main.cxx
src/Main.cxx
+1
-4
No files found.
src/LogInit.cxx
View file @
9990e847
...
...
@@ -27,9 +27,10 @@
#include "system/FatalError.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/FileSystem.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/RuntimeError.hxx"
#include "system/FatalError.hxx"
#include "system/Error.hxx"
#include <assert.h>
#include <string.h>
...
...
@@ -66,21 +67,26 @@ open_log_file(void)
return
OpenFile
(
out_path
,
O_CREAT
|
O_WRONLY
|
O_APPEND
,
0666
);
}
static
bool
log_init_file
(
int
line
,
Error
&
error
)
static
void
log_init_file
(
int
line
)
{
assert
(
!
out_path
.
IsNull
());
out_fd
=
open_log_file
();
if
(
out_fd
<
0
)
{
#ifdef WIN32
const
std
::
string
out_path_utf8
=
out_path
.
ToUTF8
();
throw
FormatRuntimeError
(
"failed to open log file
\"
%s
\"
(config line %d)"
,
out_path_utf8
.
c_str
(),
line
);
#else
int
e
=
errno
;
const
std
::
string
out_path_utf8
=
out_path
.
ToUTF8
();
error
.
FormatErrno
(
"failed to open log file
\"
%s
\"
(config line %d)"
,
throw
FormatErrno
(
e
,
"failed to open log file
\"
%s
\"
(config line %d)"
,
out_path_utf8
.
c_str
(),
line
);
return
false
;
#endif
}
EnableLogTimestamp
();
return
true
;
}
static
inline
LogLevel
...
...
@@ -114,15 +120,12 @@ log_early_init(bool verbose)
#endif
}
bool
log_init
(
bool
verbose
,
bool
use_stdout
,
Error
&
error
)
void
log_init
(
bool
verbose
,
bool
use_stdout
)
{
#ifdef ANDROID
(
void
)
verbose
;
(
void
)
use_stdout
;
(
void
)
error
;
return
true
;
#else
if
(
verbose
)
SetLogThreshold
(
LogLevel
::
DEBUG
);
...
...
@@ -130,29 +133,21 @@ log_init(bool verbose, bool use_stdout, Error &error)
SetLogThreshold
(
parse_log_level
(
param
->
value
.
c_str
(),
param
->
line
));
if
(
use_stdout
)
{
return
true
;
}
else
{
if
(
!
use_stdout
)
{
const
auto
*
param
=
config_get_param
(
ConfigOption
::
LOG_FILE
);
if
(
param
==
nullptr
)
{
#ifdef HAVE_SYSLOG
/* no configuration: default to syslog (if
available) */
LogInitSysLog
();
return
true
;
#else
error
.
Set
(
log_domain
,
"config parameter 'log_file' not found"
);
return
false
;
#ifndef HAVE_SYSLOG
throw
std
::
runtime_error
(
"config parameter 'log_file' not found"
);
#endif
#ifdef HAVE_SYSLOG
}
else
if
(
strcmp
(
param
->
value
.
c_str
(),
"syslog"
)
==
0
)
{
LogInitSysLog
();
return
true
;
#endif
}
else
{
out_path
=
param
->
GetPath
();
return
log_init_file
(
param
->
line
,
error
);
log_init_file
(
param
->
line
);
}
}
#endif
...
...
src/LogInit.hxx
View file @
9990e847
...
...
@@ -20,8 +20,6 @@
#ifndef MPD_LOG_INIT_HXX
#define MPD_LOG_INIT_HXX
class
Error
;
/**
* Configure a logging destination for daemon startup, before the
* configuration file is read. This allows the daemon to use the
...
...
@@ -33,8 +31,11 @@ class Error;
void
log_early_init
(
bool
verbose
);
bool
log_init
(
bool
verbose
,
bool
use_stdout
,
Error
&
error
);
/**
* Throws #std::runtime_error on error.
*/
void
log_init
(
bool
verbose
,
bool
use_stdout
);
void
log_deinit
();
...
...
src/Main.cxx
View file @
9990e847
...
...
@@ -412,10 +412,7 @@ try {
stats_global_init
();
TagLoadConfig
();
if
(
!
log_init
(
options
.
verbose
,
options
.
log_stderr
,
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
}
log_init
(
options
.
verbose
,
options
.
log_stderr
);
instance
=
new
Instance
();
...
...
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