Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Dunitrust
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
46
Issues
46
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nodes
rust
Dunitrust
Commits
82009e1e
Commit
82009e1e
authored
May 01, 2019
by
Éloïs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[feat] durs: add option log-stdout
parent
c3f6783d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
14 deletions
+28
-14
lib/core/core/cli/mod.rs
lib/core/core/cli/mod.rs
+3
-0
lib/core/core/lib.rs
lib/core/core/lib.rs
+25
-14
No files found.
lib/core/core/cli/mod.rs
View file @
82009e1e
...
...
@@ -43,6 +43,9 @@ pub struct DursOpt {
/// Set log level. (Defaults to INFO).
/// Available levels: [ERROR, WARN, INFO, DEBUG, TRACE]
logs_level
:
Option
<
Level
>
,
#[structopt(long
=
"log-stdout"
)]
/// Print logs in standard output
log_stdout
:
bool
,
#[structopt(subcommand)]
/// CoreSubCommand
cmd
:
CoreSubCommand
,
...
...
lib/core/core/lib.rs
View file @
82009e1e
...
...
@@ -775,6 +775,9 @@ pub fn init_logger(profile: &str, soft_name: &'static str, cli_args: &ArgMatches
_
=>
unreachable!
(
"Structopt guarantees us that the string match necessarily with one of the variants of the enum Level"
),
};
// Get log-stdout option
let
log_stdout
=
cli_args
.is_present
(
"log_stdout"
);
// Config logger
let
logger_config
=
Config
{
time
:
Some
(
Level
::
Error
),
...
...
@@ -794,20 +797,28 @@ pub fn init_logger(profile: &str, soft_name: &'static str, cli_args: &ArgMatches
.expect
(
"Fatal error : fail to create log file path !"
);
}
WriteLogger
::
init
(
log_level
.to_level_filter
(),
logger_config
,
OpenOptions
::
new
()
.write
(
true
)
.append
(
true
)
.open
(
log_file_path
.to_str
()
.expect
(
"Fatal error : fail to get log file path !"
),
)
.expect
(
"Fatal error : fail to open log file !"
),
)
.expect
(
"Fatal error : fail to init logger !"
);
let
level_filter
=
log_level
.to_level_filter
();
let
file_logger_opts
=
OpenOptions
::
new
()
.write
(
true
)
.append
(
true
)
.open
(
log_file_path
.to_str
()
.expect
(
"Fatal error : fail to get log file path !"
),
)
.expect
(
"Fatal error : fail to open log file !"
);
if
log_stdout
{
CombinedLogger
::
init
(
vec!
[
TermLogger
::
new
(
level_filter
,
logger_config
)
.expect
(
"Fatal error : fail to create term logger !"
),
WriteLogger
::
new
(
level_filter
,
logger_config
,
file_logger_opts
),
])
.expect
(
"Fatal error : Fail to init combined logger !"
);
}
else
{
WriteLogger
::
init
(
level_filter
,
logger_config
,
file_logger_opts
)
.expect
(
"Fatal error : fail to init file logger !"
);
}
info!
(
"Successfully init logger"
);
}
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