razeri_plugin_contract/procedure_log_level.rs
1// Copyright (C) 2026 Gabriel Shea
2// Licensed under either of the Apache License, Version 2.0 or the MIT
3// license, at your option.
4
5//! **How loud a message a procedure body writes is.**
6//!
7//! A generated procedure says things while it runs — that it started, how many
8//! rows it saw, that something was off but not fatal. The message is SQL the
9//! dialect is handed; the severity is not, because every engine names its
10//! levels differently and some have only one. This is the vocabulary that
11//! travels with the message.
12
13/// The severity of a message a procedure body writes.
14///
15/// It is `#[non_exhaustive]`: a dialect matching on it states a fallback rather
16/// than assuming the list it compiled against is the list that ships. An engine
17/// with one logging statement and no levels — Oracle's `DBMS_OUTPUT` is the
18/// worked case — ignores this and spells the message.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
20#[non_exhaustive]
21pub enum ProcedureLogLevel {
22 /// Detail wanted while diagnosing and not otherwise.
23 Debug,
24 /// The ordinary progress of a run, and the default.
25 #[default]
26 Info,
27 /// Something worth a reader's attention that did not stop the run.
28 Warning,
29 /// Something that went wrong. It is still a message and not a raise: a
30 /// procedure that must stop uses
31 /// [`SqlRenderer::render_procedure_raise`](crate::SqlRenderer::render_procedure_raise).
32 Error,
33}
34
35impl ProcedureLogLevel {
36 /// The level's own word, lower case — `"debug"`, `"info"`, `"warning"`,
37 /// `"error"`.
38 ///
39 /// An engine that takes a severity in its logging call reads it from here
40 /// and spells it the way that call wants:
41 /// `SYSTEM$LOG('INFO', 'loaded')` on Snowflake Scripting is
42 /// `level.as_str().to_uppercase()`.
43 #[must_use]
44 pub fn as_str(self) -> &'static str {
45 match self {
46 ProcedureLogLevel::Debug => "debug",
47 ProcedureLogLevel::Info => "info",
48 ProcedureLogLevel::Warning => "warning",
49 ProcedureLogLevel::Error => "error",
50 }
51 }
52}