#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Ord, PartialOrd, PartialEq, Eq)]
pub enum PgLogLevel {
DEBUG5 = crate::DEBUG5 as isize,
DEBUG4 = crate::DEBUG4 as isize,
DEBUG3 = crate::DEBUG3 as isize,
DEBUG2 = crate::DEBUG2 as isize,
DEBUG1 = crate::DEBUG1 as isize,
LOG = crate::LOG as isize,
#[allow(non_camel_case_types)]
LOG_SERVER_ONLY = crate::LOG_SERVER_ONLY as isize,
INFO = crate::INFO as isize,
NOTICE = crate::NOTICE as isize,
WARNING = crate::WARNING as isize,
ERROR = crate::ERROR as isize,
FATAL = crate::FATAL as isize,
PANIC = crate::PANIC as isize,
}
impl From<isize> for PgLogLevel {
#[inline]
fn from(i: isize) -> Self {
if i == PgLogLevel::DEBUG5 as isize {
PgLogLevel::DEBUG5
} else if i == PgLogLevel::DEBUG4 as isize {
PgLogLevel::DEBUG4
} else if i == PgLogLevel::DEBUG3 as isize {
PgLogLevel::DEBUG3
} else if i == PgLogLevel::DEBUG2 as isize {
PgLogLevel::DEBUG2
} else if i == PgLogLevel::DEBUG1 as isize {
PgLogLevel::DEBUG1
} else if i == PgLogLevel::INFO as isize {
PgLogLevel::INFO
} else if i == PgLogLevel::NOTICE as isize {
PgLogLevel::NOTICE
} else if i == PgLogLevel::WARNING as isize {
PgLogLevel::WARNING
} else if i == PgLogLevel::ERROR as isize {
PgLogLevel::ERROR
} else if i == PgLogLevel::FATAL as isize {
PgLogLevel::FATAL
} else if i == PgLogLevel::PANIC as isize {
PgLogLevel::PANIC
} else {
PgLogLevel::ERROR
}
}
}
impl From<i32> for PgLogLevel {
#[inline]
fn from(i: i32) -> Self {
(i as isize).into()
}
}
#[macro_export]
macro_rules! debug5 {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::DEBUG5, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! debug4 {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::DEBUG4, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! debug3 {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::DEBUG3, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! debug2 {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::DEBUG2, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! debug1 {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::DEBUG1, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! log {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::LOG, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::INFO, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! notice {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::NOTICE, $crate::errcodes::PgSqlErrorCode::ERRCODE_SUCCESSFUL_COMPLETION, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! warning {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::WARNING, $crate::errcodes::PgSqlErrorCode::ERRCODE_WARNING, alloc::format!($($arg)*).as_str());
}
)
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::ERROR, $crate::errcodes::PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, alloc::format!($($arg)*).as_str());
unreachable!()
}
);
}
#[allow(non_snake_case)]
#[macro_export]
macro_rules! FATAL {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::FATAL, $crate::errcodes::PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, alloc::format!($($arg)*).as_str());
unreachable!()
}
)
}
#[allow(non_snake_case)]
#[macro_export]
macro_rules! PANIC {
($($arg:tt)*) => (
{
extern crate alloc;
$crate::ereport!($crate::elog::PgLogLevel::PANIC, $crate::errcodes::PgSqlErrorCode::ERRCODE_INTERNAL_ERROR, alloc::format!($($arg)*).as_str());
unreachable!()
}
)
}
#[macro_export]
macro_rules! function_name {
() => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
core::any::type_name::<T>()
}
let name = type_name_of(f);
&name[..name.len() - 3]
}};
}
#[macro_export]
macro_rules! ereport {
(ERROR, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::ERROR);
unreachable!();
};
(PANIC, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::PANIC);
unreachable!();
};
(FATAL, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::FATAL);
unreachable!();
};
(WARNING, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::WARNING)
};
(NOTICE, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::NOTICE)
};
(INFO, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::INFO)
};
(LOG, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::LOG)
};
(DEBUG5, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::DEBUG5)
};
(DEBUG4, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::DEBUG4)
};
(DEBUG3, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::DEBUG3)
};
(DEBUG2, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::DEBUG2)
};
(DEBUG1, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($crate::elog::PgLogLevel::DEBUG1)
};
($loglevel:expr, $errcode:expr, $message:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.report($loglevel);
};
($loglevel:expr, $errcode:expr, $message:expr, $detail:expr) => {
$crate::panic::ErrorReport::new($errcode, $message, $crate::function_name!())
.set_detail($detail)
.report($loglevel);
};
}
#[inline]
pub fn interrupt_pending() -> bool {
#[cfg(any(feature = "pg11"))]
unsafe {
crate::InterruptPending
}
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
unsafe {
crate::InterruptPending != 0
}
}
#[macro_export]
macro_rules! check_for_interrupts {
() => {
#[cfg(any(feature = "pg11"))]
#[allow(unused_unsafe)]
unsafe {
if $crate::InterruptPending {
$crate::ProcessInterrupts();
}
}
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
#[allow(unused_unsafe)]
unsafe {
if $crate::InterruptPending != 0 {
$crate::ProcessInterrupts();
}
}
};
}