1#[allow(dead_code)]
14#[derive(Clone, Copy, Debug, Ord, PartialOrd, PartialEq, Eq)]
15pub enum PgLogLevel {
16 DEBUG5 = crate::DEBUG5 as isize,
18
19 DEBUG4 = crate::DEBUG4 as isize,
21
22 DEBUG3 = crate::DEBUG3 as isize,
24
25 DEBUG2 = crate::DEBUG2 as isize,
27
28 DEBUG1 = crate::DEBUG1 as isize,
31
32 LOG = crate::LOG as isize,
34
35 #[allow(non_camel_case_types)]
37 LOG_SERVER_ONLY = crate::LOG_SERVER_ONLY as isize,
38
39 INFO = crate::INFO as isize,
42
43 NOTICE = crate::NOTICE as isize,
45
46 WARNING = crate::WARNING as isize,
49
50 ERROR = crate::ERROR as isize,
52
53 FATAL = crate::FATAL as isize,
55
56 PANIC = crate::PANIC as isize,
58}
59
60impl From<isize> for PgLogLevel {
61 #[inline]
62 fn from(i: isize) -> Self {
63 if i == PgLogLevel::DEBUG5 as isize {
64 PgLogLevel::DEBUG5
65 } else if i == PgLogLevel::DEBUG4 as isize {
66 PgLogLevel::DEBUG4
67 } else if i == PgLogLevel::DEBUG3 as isize {
68 PgLogLevel::DEBUG3
69 } else if i == PgLogLevel::DEBUG2 as isize {
70 PgLogLevel::DEBUG2
71 } else if i == PgLogLevel::DEBUG1 as isize {
72 PgLogLevel::DEBUG1
73 } else if i == PgLogLevel::INFO as isize {
74 PgLogLevel::INFO
75 } else if i == PgLogLevel::NOTICE as isize {
76 PgLogLevel::NOTICE
77 } else if i == PgLogLevel::WARNING as isize {
78 PgLogLevel::WARNING
79 } else if i == PgLogLevel::ERROR as isize {
80 PgLogLevel::ERROR
81 } else if i == PgLogLevel::FATAL as isize {
82 PgLogLevel::FATAL
83 } else if i == PgLogLevel::PANIC as isize {
84 PgLogLevel::PANIC
85 } else {
86 PgLogLevel::ERROR
88 }
89 }
90}
91
92impl From<i32> for PgLogLevel {
93 #[inline]
94 fn from(i: i32) -> Self {
95 (i as isize).into()
96 }
97}
98
99#[macro_export]
107macro_rules! debug5 {
108 ($($arg:tt)*) => (
109 {
110 extern crate alloc;
111 $crate::ereport!($crate::elog::PgLogLevel::DEBUG5, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
112 }
113 )
114}
115
116#[macro_export]
124macro_rules! debug4 {
125 ($($arg:tt)*) => (
126 {
127 extern crate alloc;
128 $crate::ereport!($crate::elog::PgLogLevel::DEBUG4, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
129 }
130 )
131}
132
133#[macro_export]
141macro_rules! debug3 {
142 ($($arg:tt)*) => (
143 {
144 extern crate alloc;
145 $crate::ereport!($crate::elog::PgLogLevel::DEBUG3, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
146 }
147 )
148}
149
150#[macro_export]
158macro_rules! debug2 {
159 ($($arg:tt)*) => (
160 {
161 extern crate alloc;
162 $crate::ereport!($crate::elog::PgLogLevel::DEBUG2, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
163 }
164 )
165}
166
167#[macro_export]
175macro_rules! debug1 {
176 ($($arg:tt)*) => (
177 {
178 extern crate alloc;
179 $crate::ereport!($crate::elog::PgLogLevel::DEBUG1, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
180 }
181 )
182}
183
184#[macro_export]
192macro_rules! log {
193 ($($arg:tt)*) => (
194 {
195 extern crate alloc;
196 $crate::ereport!($crate::elog::PgLogLevel::LOG, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
197 }
198 )
199}
200
201#[macro_export]
206macro_rules! info {
207 ($($arg:tt)*) => (
208 {
209 extern crate alloc;
210 $crate::ereport!($crate::elog::PgLogLevel::INFO, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
211 }
212 )
213}
214
215#[macro_export]
220macro_rules! notice {
221 ($($arg:tt)*) => (
222 {
223 extern crate alloc;
224 $crate::ereport!($crate::elog::PgLogLevel::NOTICE, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
225 }
226 )
227}
228
229#[macro_export]
234macro_rules! warning {
235 ($($arg:tt)*) => (
236 {
237 extern crate alloc;
238 $crate::ereport!($crate::elog::PgLogLevel::WARNING, $crate::errcodes::PgSqlErrorCode::ERRCODE_WARNING, alloc::format!($($arg)*).as_str());
239 }
240 )
241}
242
243#[macro_export]
248macro_rules! error {
249 ($($arg:tt)*) => (
250 {
251 extern crate alloc;
252 $crate::ereport!($crate::elog::PgLogLevel::ERROR, $crate::errcodes::PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, alloc::format!($($arg)*).as_str());
253 unreachable!()
254 }
255 );
256}
257
258#[allow(non_snake_case)]
263#[macro_export]
264macro_rules! FATAL {
265 ($($arg:tt)*) => (
266 {
267 extern crate alloc;
268 $crate::ereport!($crate::elog::PgLogLevel::FATAL, $crate::errcodes::PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, alloc::format!($($arg)*).as_str());
269 unreachable!()
270 }
271 )
272}
273
274#[allow(non_snake_case)]
279#[macro_export]
280macro_rules! PANIC {
281 ($($arg:tt)*) => (
282 {
283 extern crate alloc;
284 $crate::ereport!($crate::elog::PgLogLevel::PANIC, $crate::errcodes::PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, alloc::format!($($arg)*).as_str());
285 unreachable!()
286 }
287 )
288}
289
290#[macro_export]
297macro_rules! function_name {
298 () => {{
299 fn f() {}
301 fn type_name_of<T>(_: T) -> &'static str {
302 core::any::type_name::<T>()
303 }
304 let name = type_name_of(f);
305 &name[..name.len() - 3]
307 }};
308}
309
310#[macro_export]
338macro_rules! ereport {
339 (ERROR, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
340 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
341 $(.set_detail($detail))?
342 .report($crate::elog::PgLogLevel::ERROR);
343 unreachable!();
344 };
345
346 (PANIC, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
347 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
348 $(.set_detail($detail))?
349 .report($crate::elog::PgLogLevel::PANIC);
350 unreachable!();
351 };
352
353 (FATAL, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
354 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
355 $(.set_detail($detail))?
356 .report($crate::elog::PgLogLevel::FATAL);
357 unreachable!();
358 };
359
360 (WARNING, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
361 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
362 $(.set_detail($detail))?
363 .report($crate::elog::PgLogLevel::WARNING)
364 };
365
366 (NOTICE, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
367 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
368 $(.set_detail($detail))?
369 .report($crate::elog::PgLogLevel::NOTICE)
370 };
371
372 (INFO, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
373 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
374 $(.set_detail($detail))?
375 .report($crate::elog::PgLogLevel::INFO)
376 };
377
378 (LOG, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
379 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
380 $(.set_detail($detail))?
381 .report($crate::elog::PgLogLevel::LOG)
382 };
383
384 (DEBUG5, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
385 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
386 $(.set_detail($detail))?
387 .report($crate::elog::PgLogLevel::DEBUG5)
388 };
389
390 (DEBUG4, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
391 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
392 $(.set_detail($detail))?
393 .report($crate::elog::PgLogLevel::DEBUG4)
394 };
395
396 (DEBUG3, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
397 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
398 $(.set_detail($detail))?
399 .report($crate::elog::PgLogLevel::DEBUG3)
400 };
401
402 (DEBUG2, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
403 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
404 $(.set_detail($detail))?
405 .report($crate::elog::PgLogLevel::DEBUG2)
406 };
407
408 (DEBUG1, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
409 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
410 $(.set_detail($detail))?
411 .report($crate::elog::PgLogLevel::DEBUG1)
412 };
413
414 ($loglevel:expr, $errcode:expr, $message:expr $(, $detail:expr)? $(,)?) => {
415 $crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
416 $(.set_detail($detail))?
417 .report($loglevel);
418 };
419}
420
421#[inline]
423pub fn interrupt_pending() -> bool {
424 unsafe { crate::InterruptPending != 0 }
425}
426
427#[macro_export]
430macro_rules! check_for_interrupts {
431 () => {
432 #[allow(unused_unsafe)]
433 unsafe {
434 if $crate::InterruptPending != 0 {
435 $crate::ProcessInterrupts();
436 }
437 }
438 };
439}