-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logging): Add configurable logging system with documentation (#126)
* [118] (feat on clippy-fixes) Fixed warnings for `cargo clippy -- -D warnings -W clippy::correctness -W clippy::suspicious -W clippy::complexity -W clippy::perf -W clippy::style -W clippy::pedantic` * [119] (feat on logger) Added `configuration` folder to the doc.
- Loading branch information
1 parent
8f049ac
commit 06c80be
Showing
18 changed files
with
752 additions
and
257 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,6 @@ pub mod constants; | |
|
||
// Utils methods for the board | ||
pub mod utils; | ||
|
||
// Logging | ||
pub mod logging; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use chrono::Local; | ||
use log::LevelFilter; | ||
use simplelog::{CombinedLogger, Config, WriteLogger}; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
pub fn setup_logging( | ||
config_dir: &Path, | ||
log_level: &LevelFilter, | ||
) -> Result<(), Box<dyn std::error::Error>> { | ||
match log_level { | ||
LevelFilter::Off => Ok(()), // No logging setup needed | ||
level => { | ||
// Create logs directory | ||
let log_dir = config_dir.join("logs"); | ||
fs::create_dir_all(&log_dir)?; | ||
|
||
// Create log file with timestamp | ||
let timestamp = Local::now().format("%Y-%m-%d_%H-%M-%S"); | ||
let log_file = log_dir.join(format!("chess-tui_{}.log", timestamp)); | ||
|
||
CombinedLogger::init(vec![WriteLogger::new( | ||
*level, | ||
Config::default(), | ||
fs::File::create(log_file)?, | ||
)])?; | ||
|
||
log::info!("Logging initialized at {level} level"); | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
id: display | ||
title: Display Mode | ||
sidebar_position: 2 | ||
--- | ||
|
||
import DefaultBoard from '@site/static/img/default-display-mode-board.png'; | ||
import AsciiBoard from '@site/static/img/ascii-display-mode-board.png'; | ||
|
||
# Display Mode | ||
|
||
Chess-tui supports two display modes for rendering the chess pieces: | ||
|
||
## Default Mode | ||
```toml | ||
display_mode = "DEFAULT" | ||
``` | ||
Uses Unicode chess pieces for a richer visual experience. | ||
|
||
<div style={{ textAlign: 'center', marginBottom: '20px' }}> | ||
<img src={DefaultBoard} alt="Default display mode" style={{ maxWidth: '500px' }}/> | ||
<p><em>Default mode with Unicode chess pieces</em></p> | ||
</div> | ||
|
||
## ASCII Mode | ||
```toml | ||
display_mode = "ASCII" | ||
``` | ||
Uses ASCII characters for better compatibility with terminals that don't support Unicode. | ||
|
||
<div style={{ textAlign: 'center', marginBottom: '20px' }}> | ||
<img src={AsciiBoard} alt="ASCII display mode" style={{ maxWidth: '500px' }}/> | ||
<p><em>ASCII mode for better compatibility</em></p> | ||
</div> | ||
|
||
You can toggle between display modes in-game using the menu option or by editing the configuration file. | ||
|
||
:::tip | ||
Use ASCII mode if you experience display issues with the default Unicode pieces in your terminal. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
id: engine | ||
title: Chess Engine | ||
sidebar_position: 4 | ||
--- | ||
|
||
# Chess Engine Configuration | ||
|
||
To play against a computer opponent, you need to configure a UCI-compatible chess engine. | ||
|
||
## Configuration | ||
|
||
Set the path to your chess engine in the configuration file: | ||
|
||
```toml | ||
engine_path = "/path/to/your/engine" | ||
``` | ||
|
||
## Supported Engines | ||
|
||
Any UCI-compatible chess engine should work. Some popular options include: | ||
- Stockfish | ||
- Leela Chess Zero | ||
- Komodo | ||
|
||
:::note | ||
The engine path must point to a valid UCI-compatible chess engine executable. If not configured correctly, the bot play option will be disabled. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
id: configuration-intro | ||
title: Configuration | ||
sidebar_position: 1 | ||
--- | ||
|
||
# Configuration | ||
|
||
Chess-tui can be configured through the configuration file located at `~/.config/chess-tui/config.toml`. This section covers all available configuration options. | ||
|
||
## Configuration File | ||
|
||
The configuration file is automatically created when you first run chess-tui. You can modify it manually to customize your experience: | ||
|
||
```toml | ||
# ~/.config/chess-tui/config.toml | ||
|
||
# Display mode: "DEFAULT" or "ASCII" | ||
display_mode = "DEFAULT" | ||
|
||
# Chess engine path (optional) | ||
engine_path = "/path/to/your/engine" | ||
|
||
# Logging level: "OFF", "ERROR", "WARN", "INFO", "DEBUG", or "TRACE" | ||
log_level = "OFF" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
id: logging | ||
title: Logging | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Logging | ||
|
||
Chess-tui includes a configurable logging system that can help with debugging and understanding the application's behavior. | ||
|
||
## Configuration | ||
|
||
Logging can be configured in the `~/.config/chess-tui/config.toml` file. The log level can be set using the `log_level` option: | ||
|
||
```toml | ||
log_level = "INFO" # Default is "OFF" | ||
``` | ||
|
||
### Available Log Levels | ||
|
||
- `OFF` - Logging disabled (default) | ||
- `ERROR` - Only error messages | ||
- `WARN` - Warning and error messages | ||
- `INFO` - Informational messages, warnings, and errors | ||
- `DEBUG` - Detailed debug information plus all above | ||
- `TRACE` - Most detailed logging level | ||
|
||
## Log Files | ||
|
||
When logging is enabled, log files are stored in: | ||
``` | ||
~/.config/chess-tui/logs/ | ||
``` | ||
|
||
Each log file is named with a timestamp: | ||
``` | ||
chess-tui_YYYY-MM-DD_HH-MM-SS.log | ||
``` | ||
|
||
For example: `chess-tui_2024-03-20_15-30-45.log` | ||
|
||
## Usage | ||
|
||
Logs can be helpful when: | ||
- Debugging multiplayer connection issues | ||
- Understanding game state changes | ||
- Investigating unexpected behavior | ||
- Developing new features | ||
|
||
:::tip | ||
For normal gameplay, you can leave logging set to `OFF`. Enable logging only when you need to troubleshoot issues or want to understand the application's behavior in detail. | ||
::: |
Oops, something went wrong.