Error, logs and more
Belgium Rust user group
2018-04-17
Who am I?
Grummfy
Jonathan Van Belle
@Grummfy
@Grummfy@mamot.fr
me@grummfy.be
github.com/grummfy
Open source contributor: atoum, hoa ...
Rust meetup organizer
Error, logs and more
Error
- error language vs error process
- It's normal to have
- Bad usage of the apps
- Bad behaviours from the environment
- Bad lib
- Pop some mis-usage of your libs
- ...
Logs
- troubleshooting
- performance
- usage
- audit
- stats from it
- ...
Logs
- take place
- usefull
- try to be valuable
Logs
new connection
X just connect
[2018-04-17 18:22:25]new connection: X with a login and password on mobile
[2018-04-17 18:22:25]new connection: "X" with "credentials" on "mobile" ("Android 8.0.0 / ONEPLUS A500...")
[2018-04-17 18:22:25]new connection: {user} with {type} on {source} ({model}) - {"type": "credentials", "user": "H3fAh9bppeg=xuHy8woEtOfYYI18tLM76A==BKUvKCztSNl8", "source": "mobile", "model": "Android 8.0.0 / ONEPLUS A500..."}
[2018-04-17 18:22:25] [INFO]new connection: {user} with {type} on {source} ({model}) - {"type": "credentials", "user": "H3fAh9bppeg=xuHy8woEtOfYYI18tLM76A==BKUvKCztSNl8", "source": "mobile", "model": "Android 8.0.0 / ONEPLUS A500..."}
Logs
- Standard
- RFC 5424 => syslog
- RFC 5426 => syslog over udp
- ...
- + habits
- a lot of tools to deal with them
- don't reinvent the wheel
- syslog, rsyslog, logrotate, ELK, ...
- speak to your sysadmin!
- don't reinvent the wheel
In rust
rust native - error
- Error
- !panic()
- Option|Result .expect()
- panic = 'abort' in Cargo.toml
- RUST_BACKTRACE=1
rust native - error
fn main() {
use std::error::Error;
match "xc".parse::<u32>() {
Err(e) => {
println!("1. Error parsing some value: {}", e.description());
eprintln!("2. Error parsing some value: {}", e.description());
}
_ => println!("No error"),
}
}
Demo
rust native - log
- output to screen
- file
- open a file
- format a string
- write it
- close the file
Crates?
That's a lot!
Let's choose one
that's it!
Error - crates
- simple-error
- derive-error
- yade
- failure
- error-chain
- ...
Logs - crates
- log
- env_logger
- pretty_env_logger
- simplelog
- stderrlog
- flexi_logger
- log4rs
- env_logger
- slog
Demo
crate to choose?
- error
- error-chain or yade
- log
- sloggers for a desktop app
- flexi_logger for general usage
Collecting
- sentry: https://github.com/getsentry/sentry-rust
- rollbar*: https://crates.io/crates/rollbar
- bugsnag*: https://github.com/mehcode/bugsnag-rs
- newrelic*: https://github.com/hjr3/newrelic-rs (abandoned)
- probably more...
* = unofficial
Thanks
Questions?
demo https://gitlab.com/Grummfy/brug-2018-04-17_error_logs
Error, logs and more
By Jonathan Van Belle
Error, logs and more
How to manage error and display them through your logs? How to manage it? What's important? Libs to handle it... So let's discover it and speak about it.
- 2,212