Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
00507e3b
Commit
00507e3b
authored
3 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
feat: configure log level with env var
parent
e15b7782
No related branches found
No related tags found
1 merge request
!1392
feat: configure log level with env var
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust-bins/duniter-cli/src/duniter_ts_args.rs
+7
-5
7 additions, 5 deletions
rust-bins/duniter-cli/src/duniter_ts_args.rs
rust-bins/duniter-cli/src/main.rs
+13
-2
13 additions, 2 deletions
rust-bins/duniter-cli/src/main.rs
with
20 additions
and
7 deletions
rust-bins/duniter-cli/src/duniter_ts_args.rs
+
7
−
5
View file @
00507e3b
...
...
@@ -38,16 +38,18 @@ fn gen_webstart_args(args: &DuniterWebstartArgs, duniter_ts_args: &mut Vec<Strin
}
}
pub
(
crate
)
fn
gen_duniter_ts_args
(
args
:
&
DuniterArgs
,
duniter_js_exe
:
String
)
->
Vec
<
String
>
{
pub
(
crate
)
fn
gen_duniter_ts_args
(
args
:
&
DuniterArgs
,
duniter_js_exe
:
String
,
log_level_filter
:
log
::
LevelFilter
,
)
->
Vec
<
String
>
{
let
mut
duniter_ts_args
=
vec!
[
"--max-old-space-size=4096"
.to_owned
(),
duniter_js_exe
];
if
let
Some
(
ref
home
)
=
args
.home
{
duniter_ts_args
.push
(
"--home"
.to_owned
());
duniter_ts_args
.push
(
home
.to_str
()
.expect
(
"invalid home path"
)
.to_owned
());
}
if
let
Some
(
ref
log_level
)
=
args
.log
{
duniter_ts_args
.push
(
"--loglevel"
.to_owned
());
duniter_ts_args
.push
(
log_level
.to_string
()
.to_lowercase
());
}
duniter_ts_args
.push
(
"--loglevel"
.to_owned
());
duniter_ts_args
.push
(
log_level_filter
.to_string
()
.to_lowercase
());
if
let
Some
(
ref
profile
)
=
args
.profile
{
duniter_ts_args
.push
(
"--mdb"
.to_owned
());
duniter_ts_args
.push
(
profile
.clone
());
...
...
This diff is collapsed.
Click to expand it.
rust-bins/duniter-cli/src/main.rs
+
13
−
2
View file @
00507e3b
...
...
@@ -38,7 +38,7 @@ use logwatcher::{LogWatcher, LogWatcherAction};
use
nix
::{
errno
::
Errno
,
sys
::
signal
::
Signal
,
unistd
::
Pid
,
Error
};
use
std
::{
fs
::
File
,
io
::
prelude
::
*
,
path
::
Path
,
path
::
PathBuf
,
process
::
Command
,
process
::
Output
,
process
::
Stdio
,
process
::
Stdio
,
str
::
FromStr
,
};
use
structopt
::{
clap
::
Shell
,
StructOpt
};
...
...
@@ -214,6 +214,7 @@ fn main() -> Result<()> {
DuniterArgs
::
clap
()
.gen_completions_to
(
APP_NAME
,
shell
,
&
mut
std
::
io
::
stdout
());
Ok
(())
}
else
{
let
log_level_filter
=
get_log_level
(
args
.log
)
?
;
let
profile_path
=
get_profile_path
(
args
.profile
.as_deref
())
?
;
#[cfg(feature
=
"gva"
)]
...
...
@@ -225,7 +226,8 @@ fn main() -> Result<()> {
let
prod
=
current_exe
==
PathBuf
::
from
(
DUNITER_EXE_LINK_PATH
)
||
current_exe
==
PathBuf
::
from
(
DUNITER_EXE_PATH
);
let
duniter_ts_args
=
duniter_ts_args
::
gen_duniter_ts_args
(
&
args
,
duniter_js_exe
()
?
);
let
duniter_ts_args
=
duniter_ts_args
::
gen_duniter_ts_args
(
&
args
,
duniter_js_exe
()
?
,
log_level_filter
);
match
args
.command
{
DuniterCommand
::
Restart
=>
{
...
...
@@ -325,6 +327,15 @@ pub(crate) fn get_node_version(node_path: &str) -> Result<String> {
}
}
fn
get_log_level
(
opt
:
Option
<
log
::
LevelFilter
>
)
->
Result
<
log
::
LevelFilter
>
{
if
let
Ok
(
log_level_str
)
=
std
::
env
::
var
(
"DUNITER_LOG_LEVEL"
)
{
Ok
(
log
::
LevelFilter
::
from_str
(
&
log_level_str
)
.map_err
(|
e
|
anyhow
::
Error
::
msg
(
e
.to_string
()))
?
)
}
else
{
Ok
(
opt
.unwrap_or
(
log
::
LevelFilter
::
Info
))
}
}
fn
get_profile_path
(
profile
:
Option
<&
str
>
)
->
Result
<
PathBuf
>
{
let
mut
profile_path
=
dirs
::
config_dir
()
.expect
(
"unsupported operating system"
);
profile_path
.push
(
APP_NAME
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment