Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
GSDiscover Debug Tool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Avionics
Software Development
GSDiscover Debug Tool
Commits
18bef3fb
Commit
18bef3fb
authored
3 months ago
by
Federico Lolli
Browse files
Options
Downloads
Patches
Plain Diff
improved logging
parent
2cad24b9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/cli.rs
+10
-4
10 additions, 4 deletions
src/cli.rs
src/log.rs
+22
-2
22 additions, 2 deletions
src/log.rs
src/log/formatter.rs
+1
-1
1 addition, 1 deletion
src/log/formatter.rs
src/log/handler.rs
+5
-8
5 additions, 8 deletions
src/log/handler.rs
src/main.rs
+6
-5
6 additions, 5 deletions
src/main.rs
with
44 additions
and
20 deletions
src/cli.rs
+
10
−
4
View file @
18bef3fb
...
...
@@ -2,7 +2,7 @@ use std::time::Duration;
use
clap
::{
Parser
,
Subcommand
};
use
crate
::
log
::
LogFormatter
;
use
crate
::
log
::
{
LogFormatter
,
LogLevel
}
;
#[derive(Debug,
Clone,
Parser)]
#[command(version,
about,
infer_subcommands
=
true
)]
...
...
@@ -13,8 +13,8 @@ pub struct Cli {
pub
time
:
bool
,
/// Enable verbose output (prints more information).
#[arg(short,
long)]
pub
verbose
:
bool
,
#[arg(short,
long
,
action
=
clap::ArgAction::Count
)]
pub
verbose
:
u8
,
#[command(subcommand)]
pub
command
:
Subcommands
,
...
...
@@ -73,9 +73,15 @@ impl DiscoverOptions {
impl
From
<&
Cli
>
for
LogFormatter
{
fn
from
(
value
:
&
Cli
)
->
Self
{
let
level
=
match
value
.verbose
{
0
=>
LogLevel
::
Info
,
1
=>
LogLevel
::
Debug
,
_
=>
LogLevel
::
Trace
,
};
LogFormatter
{
show_time
:
value
.time
,
show_debug
:
value
.verbose
,
level
,
}
}
}
This diff is collapsed.
Click to expand it.
src/log.rs
+
22
−
2
View file @
18bef3fb
...
...
@@ -10,17 +10,26 @@ pub use formatter::LogFormatter;
pub
static
LOG_HANDLER
:
LazyLock
<
LogHandler
>
=
LazyLock
::
new
(
LogHandler
::
default
);
#[derive(Debug,
Clone,
Copy)]
enum
LogLevel
{
#[derive(Debug,
Clone,
Copy,
PartialEq,
PartialOrd,
Default)]
pub
enum
LogLevel
{
Trace
,
Debug
,
#[default]
Info
,
Warning
,
Error
,
}
impl
std
::
fmt
::
Display
for
LogLevel
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
write!
(
f
,
"{:?}"
,
self
)
}
}
impl
LogLevel
{
fn
symbol_prepend
(
&
self
)
->
char
{
match
self
{
LogLevel
::
Trace
=>
'&'
,
LogLevel
::
Debug
=>
'@'
,
LogLevel
::
Info
=>
'*'
,
LogLevel
::
Warning
=>
'#'
,
...
...
@@ -30,6 +39,7 @@ impl LogLevel {
fn
style
(
&
self
)
->
Style
{
match
self
{
LogLevel
::
Trace
=>
Style
::
new
()
.cyan
(),
LogLevel
::
Debug
=>
Style
::
new
()
.green
(),
LogLevel
::
Info
=>
Style
::
new
()
.blue
(),
LogLevel
::
Warning
=>
Style
::
new
()
.yellow
(),
...
...
@@ -38,6 +48,16 @@ impl LogLevel {
}
}
#[macro_export]
macro_rules!
trace
{
(
$input:expr
)
=>
{{
$crate
::
log
::
LOG_HANDLER
.print_trace
(
$input
);
}};
(
$input:expr
,
$
(
$args:expr
),
+
)
=>
{{
$crate
::
log
::
LOG_HANDLER
.print_trace
(
format!
(
$input
,
$
(
$args
),
+
));
}};
}
#[macro_export]
macro_rules!
debug
{
(
$input:expr
)
=>
{{
...
...
This diff is collapsed.
Click to expand it.
src/log/formatter.rs
+
1
−
1
View file @
18bef3fb
...
...
@@ -6,7 +6,7 @@ use super::LogLevel;
#[derive(Debug,
Clone,
Default)]
pub
struct
LogFormatter
{
pub
show_time
:
bool
,
pub
show_debug
:
boo
l
,
pub
level
:
LogLeve
l
,
}
impl
LogFormatter
{
...
...
This diff is collapsed.
Click to expand it.
src/log/handler.rs
+
5
−
8
View file @
18bef3fb
...
...
@@ -25,19 +25,16 @@ macro_rules! define_print {
(
$name:ident
,
$level:ident
)
=>
{
#[inline]
pub
fn
$name
(
&
self
,
input
:
impl
AsRef
<
str
>
)
{
if
self
.formatter
.read
()
.unwrap
()
.level
<=
LogLevel
::
$level
{
self
.print_with
(
input
.as_ref
(),
LogLevel
::
$level
);
}
}
};
}
impl
LogHandler
{
#[inline]
pub
fn
print_debug
(
&
self
,
input
:
impl
AsRef
<
str
>
)
{
if
self
.formatter
.read
()
.unwrap
()
.show_debug
{
self
.print_with
(
input
.as_ref
(),
LogLevel
::
Debug
);
}
}
define_print!
(
print_trace
,
Trace
);
define_print!
(
print_debug
,
Debug
);
define_print!
(
print_info
,
Info
);
define_print!
(
print_warn
,
Warning
);
define_print!
(
print_error
,
Error
);
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
6
−
5
View file @
18bef3fb
...
...
@@ -38,8 +38,9 @@ const DEFAULT_MAVLINK_PORT: u16 = 14551;
fn
main
()
{
// parse args and set up logging
let
args
=
Cli
::
parse
();
LOG_HANDLER
.set_formatter
(
LogFormatter
::
from
(
&
args
));
debug!
(
"Debug mode: {}"
,
args
.verbose
);
let
fmt
=
LogFormatter
::
from
(
&
args
);
LOG_HANDLER
.set_formatter
(
fmt
.clone
());
debug!
(
"Log mode: {}"
,
fmt
.level
.to_string
()
.to_uppercase
());
// run the command
run_command
(
&
args
)
.unwrap_or_else
(|
e
|
{
...
...
@@ -84,7 +85,7 @@ fn wait_for_interface(wait_for: Duration) -> PResult<Ipv4Addr> {
Ok
(
ip
)
}
None
=>
{
debug
!
(
"No link-local address found, retrying in 1s..."
);
trace
!
(
"No link-local address found, retrying in 1s..."
);
Err
(
StepError
::
Timeout
)
}
}
...
...
@@ -217,7 +218,7 @@ fn handle_discover_replies(
MessageReadError
::
Io
(
e
)
if
e
.kind
()
==
ErrorKind
::
WouldBlock
||
e
.kind
()
==
ErrorKind
::
TimedOut
=>
{
debug
!
(
"No message received, retrying..."
);
trace
!
(
"No message received, retrying..."
);
Err
(
StepError
::
Timeout
)
}
_
=>
{
...
...
@@ -280,7 +281,7 @@ fn handle_discover_requests(
MessageReadError
::
Io
(
e
)
if
e
.kind
()
==
ErrorKind
::
WouldBlock
||
e
.kind
()
==
ErrorKind
::
TimedOut
=>
{
debug
!
(
"No message received, retrying..."
);
trace
!
(
"No message received, retrying..."
);
Err
(
StepError
::
Timeout
)
}
_
=>
{
...
...
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