Skip to content

Commit

Permalink
chore: add log-level-error feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jun 16, 2024
1 parent 325ab03 commit ea6e3df
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ els = ["erg_common/els", "erg_compiler/els", "dep:els"]
full-repl = ["erg_common/full-repl"]
full = ["els", "full-repl", "unicode", "pretty"]
experimental = ["erg_common/experimental", "erg_parser/experimental", "erg_compiler/experimental", "erg_linter/experimental"]
log-level-error = ["erg_common/log-level-error", "erg_parser/log-level-error", "erg_compiler/log-level-error", "erg_linter/log-level-error"]

[workspace.dependencies]
erg_common = { version = "0.6.37", path = "./crates/erg_common" }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ no_std = []
full-repl = ["dep:crossterm"]
experimental = []
pylib = ["dep:pyo3"]
log-level-error = []

[target.'cfg(unix)'.dependencies]
backtrace-on-stack-overflow = { version = "0.3.0", optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_common/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub const PYTHON_MODE: bool = cfg!(feature = "py_compat");
pub const ERG_MODE: bool = !cfg!(feature = "py_compat");
pub const ELS: bool = cfg!(feature = "els");
pub const DEBUG_MODE: bool = cfg!(feature = "debug");
pub const LOG_LEVEL_ERROR: bool = cfg!(feature = "log-level-error");
pub const EXPERIMENTAL_MODE: bool = cfg!(feature = "experimental");
pub const BACKTRACE_MODE: bool = cfg!(feature = "backtrace");
pub const GAL: bool = cfg!(feature = "gal");
9 changes: 9 additions & 0 deletions crates/erg_common/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ impl<K, V> IntoIterator for Dict<K, V> {
}
}

impl<'a, K, V> IntoIterator for &'a Dict<K, V> {
type Item = (&'a K, &'a V);
type IntoIter = Iter<'a, K, V>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
self.dict.iter()
}
}

impl<K: Hash + Eq, V> Dict<K, V> {
#[inline]
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Expand Down
10 changes: 7 additions & 3 deletions crates/erg_common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,19 @@ macro_rules! debug_info {
#[macro_export]
macro_rules! log {
(info $($arg: tt)*) => {{
$crate::log!(c DEBUG_MAIN, $($arg)*);
if !$crate::consts::LOG_LEVEL_ERROR {
$crate::log!(c DEBUG_MAIN, $($arg)*);
}
}};

(err $($arg: tt)*) => {{
$crate::log!(c DEBUG_ERROR, $($arg)*);
}};

(info_f $output:ident, $($arg: tt)*) => {{
$crate::log!(f+c $output, DEBUG_MAIN, $($arg)*);
if !$crate::consts::LOG_LEVEL_ERROR {
$crate::log!(f+c $output, DEBUG_MAIN, $($arg)*);
}
}};

(err_f $output:ident, $($arg: tt)*) => {{
Expand Down Expand Up @@ -533,7 +537,7 @@ macro_rules! log {
}};

($($arg: tt)*) => {{
if cfg!(feature = "debug") {
if cfg!(feature = "debug") && !$crate::consts::LOG_LEVEL_ERROR {
use $crate::style::*;
$crate::debug_info!();
println!($($arg)*);
Expand Down
10 changes: 10 additions & 0 deletions crates/erg_common/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ impl<T: Hash> IntoIterator for Set<T> {
}
}

impl<'a, T> IntoIterator for &'a Set<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

#[inline]
fn into_iter(self) -> Iter<'a, T> {
self.elems.iter()
}
}

impl<T: Hash + Eq> Set<T> {
#[inline]
pub fn get<Q>(&self, value: &Q) -> Option<&T>
Expand Down
1 change: 1 addition & 0 deletions crates/erg_common/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl<T: Clone> Shared<T> {

/// Thread-local objects that can be shared among threads.
/// The initial value can be shared globally, but the changes are not reflected in other threads.
/// If you want to reflect the changes in other threads, you need to call `update_init`.
/// Otherwise, this behaves as a `RefCell`.
#[derive(Clone)]
pub struct Forkable<T: Send + Clone> {
Expand Down
1 change: 1 addition & 0 deletions crates/erg_compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ full-repl = ["erg_common/full-repl"]
experimental = ["erg_common/experimental", "erg_parser/experimental"]
pylib = ["dep:pyo3", "erg_common/pylib", "erg_parser/pylib"]
pylib_compiler = ["pylib"]
log-level-error = ["erg_common/log-level-error", "erg_parser/log-level-error"]

[dependencies]
erg_common = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ gal = ["erg_common/gal", "erg_compiler/gal"]
full-repl = ["erg_common/full-repl"]
full = ["full-repl", "unicode", "pretty"]
experimental = ["erg_common/experimental", "erg_parser/experimental", "erg_compiler/experimental"]
log-level-error = ["erg_common/log-level-error", "erg_parser/log-level-error", "erg_compiler/log-level-error"]

[dependencies]
erg_common = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ large_thread = ["erg_common/large_thread"]
experimental = ["erg_common/experimental"]
pylib = ["dep:pyo3", "erg_common/pylib"]
pylib_parser = ["pylib"]
log-level-error = ["erg_common/log-level-error"]

[dependencies]
erg_common = { workspace = true }
Expand Down
8 changes: 8 additions & 0 deletions doc/EN/dev_guide/build_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ Increase the thread stack size. Used for Windows execution and test execution.
## py_compatible

Enable Python-compatible mode, which makes parts of the APIs and syntax compatible with Python. Used for [pylyzer](https://github.com/mtshiba/pylyzer).

## experimental

Enable experimental features.

## log-level-error

Only display error logs.
8 changes: 8 additions & 0 deletions doc/JA/dev_guide/build_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ Erg 内部オプション、ヘルプ (ヘルプ、著作権、ライセンス
## py_compatible

Python互換モードを有効にする。APIや文法の一部がPythonと互換になる。[pylyzer](https://github.com/mtshiba/pylyzer)のために使用される。

## experimental

実験的な機能を有効にする。

## log-level-error

エラーログのみ表示する。

0 comments on commit ea6e3df

Please sign in to comment.