libnotcurses_sys/log_level.rs
1//!
2
3/// Log level for [`NcOptions`][crate::NcOptions].
4///
5/// # Default
6///
7/// These log levels consciously map cleanly to those of libav; notcurses itself
8/// does not use this full granularity.
9///
10/// The log level does not affect the opening and closing banners,
11/// which can be disabled via [`NcFlag::SuppressBanners`]
12///
13/// [`NcFlag::SuppressBanners`]: crate::NcFlag#associatedconstant.SuppressBanners
14///
15/// Note that if stderr is connected to the same terminal on which we're
16/// rendering, any kind of logging will disrupt the output.
17#[repr(i32)]
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum NcLogLevel {
20 /// Default. print nothing once fullscreen service begins.
21 Silent = c_api::NCLOGLEVEL_SILENT,
22
23 /// Print diagnostics immediately related to crashing.
24 Panic = c_api::NCLOGLEVEL_PANIC,
25
26 /// We're hanging around, but we've had a horrible fault.
27 Fatal = c_api::NCLOGLEVEL_FATAL,
28
29 /// We can't keep doin' this, but we can do other things.
30 Error = c_api::NCLOGLEVEL_ERROR,
31
32 /// You probably don't want what's happening to happen.
33 Warning = c_api::NCLOGLEVEL_WARNING,
34
35 /// "Standard information".
36 Info = c_api::NCLOGLEVEL_INFO,
37
38 /// "Detailed information".
39 Verbose = c_api::NCLOGLEVEL_VERBOSE,
40
41 /// This is honestly a bit much.
42 Debug = c_api::NCLOGLEVEL_DEBUG,
43
44 /// There's probably a better way to do what you want.
45 Trace = c_api::NCLOGLEVEL_TRACE,
46}
47
48mod core_impls {
49 use super::{c_api, NcLogLevel};
50 use core::fmt;
51
52 impl Default for NcLogLevel {
53 fn default() -> Self {
54 Self::Silent
55 }
56 }
57
58 impl fmt::Display for NcLogLevel {
59 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60 use NcLogLevel::*;
61 write!(
62 f,
63 "{}",
64 match self {
65 Silent => "Silent",
66 Panic => "Panic",
67 Fatal => "Fatal",
68 Error => "Error",
69 Warning => "Warning",
70 Info => "Info",
71 Verbose => "Verbose",
72 Debug => "Debug",
73 Trace => "Trace",
74 }
75 )
76 }
77 }
78
79 impl From<c_api::NcLogLevel_i32> for NcLogLevel {
80 fn from(log_level: c_api::NcLogLevel_i32) -> Self {
81 use {c_api::*, NcLogLevel::*};
82 match log_level {
83 NCLOGLEVEL_SILENT => Silent,
84 NCLOGLEVEL_PANIC => Panic,
85 NCLOGLEVEL_FATAL => Fatal,
86 NCLOGLEVEL_ERROR => Error,
87 NCLOGLEVEL_WARNING => Warning,
88 NCLOGLEVEL_INFO => Info,
89 NCLOGLEVEL_VERBOSE => Verbose,
90 NCLOGLEVEL_DEBUG => Debug,
91 NCLOGLEVEL_TRACE => Trace,
92 _ => Self::default(),
93 }
94 }
95 }
96
97 impl From<NcLogLevel> for c_api::NcLogLevel_i32 {
98 fn from(loglevel: NcLogLevel) -> Self {
99 use {c_api::*, NcLogLevel::*};
100 match loglevel {
101 Silent => NCLOGLEVEL_SILENT,
102 Panic => NCLOGLEVEL_PANIC,
103 Fatal => NCLOGLEVEL_FATAL,
104 Error => NCLOGLEVEL_ERROR,
105 Warning => NCLOGLEVEL_WARNING,
106 Info => NCLOGLEVEL_INFO,
107 Verbose => NCLOGLEVEL_VERBOSE,
108 Debug => NCLOGLEVEL_DEBUG,
109 Trace => NCLOGLEVEL_TRACE,
110 }
111 }
112 }
113}
114
115pub(crate) mod c_api {
116 use crate::c_api::ffi;
117
118 /// Log level for [`NcOptions`][crate::NcOptions].
119 ///
120 /// It's recommended to use [`NcLogLevel`][crate::NcLogLevel] instead.
121 ///
122 /// # Associated `c_api` constants
123 /// - [`NCLOGLEVEL_SILENT`]
124 /// - [`NCLOGLEVEL_PANIC`]
125 /// - [`NCLOGLEVEL_FATAL`]
126 /// - [`NCLOGLEVEL_ERROR`]
127 /// - [`NCLOGLEVEL_WARNING`]
128 /// - [`NCLOGLEVEL_INFO`]
129 /// - [`NCLOGLEVEL_VERBOSE`]
130 /// - [`NCLOGLEVEL_DEBUG`]
131 /// - [`NCLOGLEVEL_TRACE`]
132 ///
133 /// These log levels consciously map cleanly to those of libav; notcurses itself
134 /// does not use this full granularity. The log level does not affect the opening
135 /// and closing banners, which can be disabled via the `NcOptions`
136 /// `NCOPTION_SUPPRESS_BANNERS`.
137 ///
138 /// Note that if stderr is connected to the same terminal on which we're
139 /// rendering, any kind of logging will disrupt the output.
140 pub type NcLogLevel_i32 = ffi::ncloglevel_e;
141
142 /// [`NcLogLevel_i32`] default. print nothing once fullscreen service begins.
143 pub const NCLOGLEVEL_SILENT: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_SILENT;
144
145 /// [`NcLogLevel_i32`] print diagnostics immediately related to crashing.
146 pub const NCLOGLEVEL_PANIC: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_PANIC;
147
148 /// [`NcLogLevel_i32`] we're hanging around, but we've had a horrible fault.
149 pub const NCLOGLEVEL_FATAL: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_FATAL;
150
151 /// [`NcLogLevel_i32`] we can't keep doin' this, but we can do other things.
152 pub const NCLOGLEVEL_ERROR: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_ERROR;
153
154 /// [`NcLogLevel_i32`] you probably don't want what's happening to happen.
155 pub const NCLOGLEVEL_WARNING: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_WARNING;
156
157 /// [`NcLogLevel_i32`] "detailed information.
158 pub const NCLOGLEVEL_INFO: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_INFO;
159
160 /// [`NcLogLevel_i32`] "detailed information.
161 pub const NCLOGLEVEL_VERBOSE: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_VERBOSE;
162
163 /// [`NcLogLevel_i32`] this is honestly a bit much.
164 pub const NCLOGLEVEL_DEBUG: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_DEBUG;
165
166 /// [`NcLogLevel_i32`] there's probably a better way to do what you want.
167 pub const NCLOGLEVEL_TRACE: NcLogLevel_i32 = ffi::ncloglevel_e_NCLOGLEVEL_TRACE;
168}