https://github.com/coderkearns/quicklog
A quick-and-dirty python logger that's extensible by design.
https://github.com/coderkearns/quicklog
Last synced: 3 months ago
JSON representation
A quick-and-dirty python logger that's extensible by design.
- Host: GitHub
- URL: https://github.com/coderkearns/quicklog
- Owner: coderkearns
- License: mit
- Created: 2022-02-09T17:24:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-24T20:57:24.000Z (almost 4 years ago)
- Last Synced: 2026-01-05T22:20:20.293Z (6 months ago)
- Language: Python
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Quicklog
A quick-and-dirty logger for python that's extensible by design.
## Installation
### Pip (recommended)
```bash
$ pip install coderkearns_quicklog
```
### Git
```bash
$ python -m pip install git+https://github.com/coderkearns/quicklog.git
```
## API Reference
### BaseLogger
In [`base.py`](base.py). Extensible but unusable on its own. All other loggers should extend this class and implement a `log(level, *args)` method.
#### `BaseLogger.LEVELS`
A dict of all the log levels.
| Number | Name |
| :----- | :--- |
| `0` | `"DEBUG" ` |
| `1` | `"INFO"` |
| `2` | `"WARNING"` |
| `3` | `"ERROR"` |
| `4` | `"CRITICAL"` |
| `5` | `"FATAL"` |
#### `BaseLogger.get_level(level_name)`
Gets a level number from the given name.
```python
BaseLogger.get_level("ERROR") # => 3
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `level_name` | `str` | **Required**. The name of the level. |
#### `BaseLogger.get_level_name(self, level)`
Gets a level name given its number.
```python
BaseLogger.get_level_name(3) # => "ERROR"
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `level` | `int` | **Required**. The number of the level. |
#### `__init__(level=1)`
```python
logger = BaseLogger(level)
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `level` | `int⎮string` | **Optional**, default `1`. The level to show. Can be the level's number or the level's name. |
#### `set_level(level)`
Changes the minimum level to log to `level`
```python
logger = BaseLogger(1) # INFO
logger.set_level(0) # DEBUG
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `level` | `int` | **Required**. The level to show. |
#### `debug(*args)`
Logs a *DEBUG* level message.
```python
logger.debug("some debug") # [DEBUG] some debug
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `*args` | `any` | The values to log. |
#### `info(*args)`
Logs a *INFO* level message.
```python
logger.info("some info") # [INFO] some info
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `*args` | `any` | The values to log. |
#### `warning(*args)`
Logs a *WARNING* level message.
```python
logger.warning("some warning") # [WARNING] some warning
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `*args` | `any` | The values to log. |
#### `error(*args)`
Logs a *ERROR* level message.
```python
logger.error("some error") # [ERROR] some error
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `*args` | `any` | The values to log. |
#### `critical(*args)`
Logs a *CRITICAL* level message.
```python
logger.critical("some critical") # [CRITICAL] some critical
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `*args` | `any` | The values to log. |
#### `fatal(*args)`
Logs a *FATAL* level message.
```python
logger.fatal("some fatal") # [FATAL] some fatal
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `*args` | `any` | The values to log. |
### FileLogger
In [`file.py`](file.py). Stores it's logs in a file.
#### `__init__(path, level=1)`
Creates a new FileLogger for the given path.
```python
file_logger = FileLogger("./filelogs.log", "ERROR")
```
| Parameter | Type | Description |
| :-------- | :------- | :------------------------- |
| `path` | `str` | The path to the log file. It it does not exist, create it. |
#### `log(level, *args)`
Appends a log the the log file.
Formatted as `[] `
#### `open()`
Opens the file at the given path.
#### `close()`
Closes the file at the given path.
### MemoryLogger
In [`memory.py`](memory.py). Stores it's logs in a list.
#### `log(level, *args)`
Adds a log to the internal list.
Formatted as `["", ]`
#### `get_logs()`
Returns a list with all the logs in the format `[level_name, *args]`
```python
memory_logger.debug("a")
memory_logger.error("b", 1)
memory_logger.get_logs()
# => [["DEBUG", "a"], ["ERROR", "b", 1]]
```
### StdoutLogger
In [`stdout.py`](stdout.py). Logs to the stdout using `print()`.
#### `log(level, *args)`
Prints a log to the stdout.
Formatted as `[] `
## License
[MIT](https://choosealicense.com/licenses/mit/)