Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
polkadot
Commits
cbe33cb8
Commit
cbe33cb8
authored
Apr 18, 2018
by
Arkadiy Paronyan
Committed by
asynchronous rob
Apr 18, 2018
Browse files
Improved logging (#138)
* Improved logging * Removed some unwraps
parent
55fbc7f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
cli/Cargo.toml
View file @
cbe33cb8
...
...
@@ -9,6 +9,11 @@ clap = { version = "2.27", features = ["yaml"] }
env_logger
=
"0.4"
error-chain
=
"0.11"
log
=
"0.3"
atty
=
"0.2"
regex
=
"0.2"
time
=
"0.1"
ansi_term
=
"0.10"
lazy_static
=
"1.0"
hex-literal
=
"0.1"
triehash
=
"0.1"
ed25519
=
{
path
=
"../../substrate/ed25519"
}
...
...
cli/src/informant.rs
View file @
cbe33cb8
...
...
@@ -45,7 +45,7 @@ pub fn start(service: &Service, handle: reactor::Handle) {
(
SyncState
::
Downloading
,
None
)
=>
"Syncing"
.into
(),
(
SyncState
::
Downloading
,
Some
(
n
))
=>
format!
(
"Syncing, target=#{}"
,
n
),
};
println!
(
"{} ({} peers), best: #{} ({})"
,
status
,
sync_status
.num_peers
,
best_block
.number
,
hash
)
info!
(
target
:
"polkadot"
,
"{} ({} peers), best: #{} ({})"
,
status
,
sync_status
.num_peers
,
best_block
.number
,
hash
)
}
else
{
warn!
(
"Error getting best block information"
);
}
...
...
@@ -62,5 +62,3 @@ pub fn start(service: &Service, handle: reactor::Handle) {
handle
.spawn
(
display_block_import
);
}
cli/src/lib.rs
View file @
cbe33cb8
...
...
@@ -20,6 +20,10 @@
extern
crate
app_dirs
;
extern
crate
env_logger
;
extern
crate
atty
;
extern
crate
ansi_term
;
extern
crate
regex
;
extern
crate
time
;
extern
crate
futures
;
extern
crate
tokio_core
;
extern
crate
ctrlc
;
...
...
@@ -37,6 +41,8 @@ extern crate polkadot_executor;
extern
crate
polkadot_runtime
;
extern
crate
polkadot_service
as
service
;
#[macro_use]
extern
crate
lazy_static
;
#[macro_use]
extern
crate
clap
;
#[macro_use]
...
...
@@ -183,7 +189,7 @@ fn start_server<T, F>(mut address: SocketAddr, start: F) -> Result<T, io::Error>
}
fn
parse_address
(
default
:
&
str
,
port_param
:
&
str
,
matches
:
&
clap
::
ArgMatches
)
->
Result
<
SocketAddr
,
String
>
{
let
mut
address
:
SocketAddr
=
default
.parse
()
.
unwrap
()
;
let
mut
address
:
SocketAddr
=
default
.parse
()
.
ok
()
.ok_or
(
format!
(
"Invalid address specified for --{}."
,
port_param
))
?
;
if
let
Some
(
port
)
=
matches
.value_of
(
port_param
)
{
let
port
:
u16
=
port
.parse
()
.ok
()
.ok_or
(
format!
(
"Invalid port for --{} specified."
,
port_param
))
?
;
address
.set_port
(
port
);
...
...
@@ -219,6 +225,8 @@ fn default_base_path() -> PathBuf {
}
fn
init_logger
(
pattern
:
&
str
)
{
use
ansi_term
::
Colour
;
let
mut
builder
=
env_logger
::
LogBuilder
::
new
();
// Disable info logging by default for some modules:
builder
.filter
(
Some
(
"ws"
),
log
::
LogLevelFilter
::
Warn
);
...
...
@@ -231,7 +239,37 @@ fn init_logger(pattern: &str) {
}
builder
.parse
(
pattern
);
let
isatty
=
atty
::
is
(
atty
::
Stream
::
Stderr
);
let
enable_color
=
isatty
;
let
format
=
move
|
record
:
&
log
::
LogRecord
|
{
let
timestamp
=
time
::
strftime
(
"%Y-%m-%d %H:%M:%S"
,
&
time
::
now
())
.expect
(
"Error formatting log timestamp"
);
let
mut
output
=
if
log
::
max_log_level
()
<=
log
::
LogLevelFilter
::
Info
{
format!
(
"{} {}"
,
Colour
::
Black
.bold
()
.paint
(
timestamp
),
record
.args
())
}
else
{
let
name
=
::
std
::
thread
::
current
()
.name
()
.map_or_else
(
Default
::
default
,
|
x
|
format!
(
"{}"
,
Colour
::
Blue
.bold
()
.paint
(
x
)));
format!
(
"{} {} {} {} {}"
,
Colour
::
Black
.bold
()
.paint
(
timestamp
),
name
,
record
.level
(),
record
.target
(),
record
.args
())
};
if
!
enable_color
{
output
=
kill_color
(
output
.as_ref
());
}
if
!
isatty
&&
record
.level
()
<=
log
::
LogLevel
::
Info
&&
atty
::
is
(
atty
::
Stream
::
Stdout
)
{
// duplicate INFO/WARN output to console
println!
(
"{}"
,
output
);
}
output
};
builder
.format
(
format
);
builder
.init
()
.expect
(
"Logger initialized only once."
);
}
fn
kill_color
(
s
:
&
str
)
->
String
{
lazy_static!
{
static
ref
RE
:
regex
::
Regex
=
regex
::
Regex
::
new
(
"
\x1b\\
[[^m]+m"
)
.expect
(
"Error initializing color regex"
);
}
RE
.replace_all
(
s
,
""
)
.to_string
()
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment