Skip to main content

PanicLog

Struct PanicLog 

Source
pub struct PanicLog { /* private fields */ }
Expand description

An owned, lossless log. It may contain zero, one, or multiple panics.

Implementations§

Source§

impl PanicLog

Source

pub fn parse(input: impl AsRef<str>) -> Self

Parse UTF-8 text, including ordinary messages and incomplete excerpts.

Source

pub fn lines(&self) -> &[LogLine]

Lines in their original order, including blank lines.

Examples found in repository?
examples/parse.rs (line 49)
11fn main() -> Result<(), Box<dyn Error>> {
12    let mut debug = false;
13    let mut path = None;
14    let mut positional_only = false;
15    for argument in env::args_os().skip(1) {
16        if !positional_only && argument == "--debug" {
17            debug = true;
18        } else if !positional_only && argument == "--" {
19            positional_only = true;
20        } else if !positional_only && (argument == "--help" || argument == "-h") {
21            println!(
22                "Usage: parse [--debug] [--] [path/to/panic.log]\nReads stdin when no path is supplied.\n--debug prints the parsed Rust structure to stdout."
23            );
24            return Ok(());
25        } else if (!positional_only && argument.to_string_lossy().starts_with('-'))
26            || path.is_some()
27        {
28            return Err(io::Error::new(
29                io::ErrorKind::InvalidInput,
30                "Usage: parse [--debug] [--] [path/to/panic.log]",
31            )
32            .into());
33        } else {
34            path = Some(argument);
35        }
36    }
37    let text = if let Some(path) = path {
38        fs::read_to_string(path)?
39    } else {
40        let mut text = String::new();
41        io::stdin().read_to_string(&mut text)?;
42        text
43    };
44    let log = parse(text);
45    if debug {
46        println!("{log:#?}");
47        return Ok(());
48    }
49    for line in log.lines() {
50        match line.kind() {
51            LineKind::Panic { message } => eprintln!("panic: {message}"),
52            LineKind::Cpu {
53                cpu,
54                uid,
55                pid,
56                details,
57            } => {
58                eprintln!("cpu: {cpu}, uid: {uid:?}, pid: {pid}, {details}");
59                if let Some(time) = line.timestamp() {
60                    eprintln!("wall time: {time}");
61                }
62                if let Some(uptime) = line.uptime() {
63                    eprintln!("uptime: {uptime}");
64                }
65            }
66            LineKind::Symbol {
67                label,
68                segment,
69                frame,
70            } => {
71                eprintln!(
72                    "{label}: segment {segment:?}, {}+{}/{}",
73                    frame.symbol, frame.offset, frame.size
74                );
75            }
76            LineKind::Diagnostic { label, details }
77                if matches!(label.as_str(), "Oops" | "BUG" | "#PF") =>
78            {
79                eprintln!("{label}: {details}");
80            }
81            LineKind::Frame(frame) => {
82                eprintln!("frame: {}+{}/{}", frame.symbol, frame.offset, frame.size)
83            }
84            _ => {}
85        }
86    }
87    // Original log goes to stdout; summaries go to stderr.
88    print!("{log}");
89    Ok(())
90}
Source

pub fn panic_messages(&self) -> impl Iterator<Item = &str>

Recognized panic messages, in their original order.

Source

pub fn has_panic(&self) -> bool

Whether a Kernel panic - not syncing: marker was found.

Trait Implementations§

Source§

impl Clone for PanicLog

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PanicLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PanicLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PanicLog

Source§

impl FromStr for PanicLog

Source§

type Err = !

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for PanicLog

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PanicLog

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.