Convenience of configuration and logging.
Project description
Yirgachefe
A library for the convenience of configuring environment variables, configuration files, and logger.
Prerequisite
- Python 3.9.x
Quick start
The configuration file format is JSON, and the default location is [CWD]/configure.json.
- CWD: Current working directory (you can get it with 'os.getcwd()')
Example configure.json
{
"API_PORT": 8100,
"STORAGE_ID": "storage_1"
}
Example Code
from yirgachefe import config, logger
logger.debug(config['API_PORT'])
logger.info(config.API_PORT)
config['NEW'] = 'new value'
config.NEW2 = 'new value2'
Custom Usage
Default configure.json.
- This value is set internally and is used even if the file doesn't exist.
- You can use the changed value by explicitly setting it in the file.
{
"debug": false,
"log_level": "WARNING",
"log_format": "%(asctime)s,%(msecs)03d %(process)d %(thread)d %(levelname)s %(filename)s(%(lineno)d) %(message)s",
"log_path": "project-sample.log"
}
- debug: Set stream handler to logging with coloredlog.
- log_level: Log level for logging.
- log_format: Log format for logging.
- log_path: Write a file log if present (optional)
Optional configuration for RotatingFileHandler.
- yirgachefe supports time-based log file rotating.
- Each option is as follows.
- Rotating works when all values are present.
{
"log_when": "d",
"log_interval": 1,
"log_backup_count": 10
}
- log_when: rotating unit s | m | h | d | w0-w6 (see. 'logging.handler')
- log_interval: rotating period
- log_backup_count: log backup count.
Make and Save configure.json
- After creating an empty config class, you can set the config value and save it as a file.
from yirgachefe import Config
config = Config()
config.NEW = 'new value'
config.write_config()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yirgachefe-0.1.2.tar.gz
(10.8 kB
view hashes)
Built Distribution
yirgachefe-0.1.2-py3-none-any.whl
(11.5 kB
view hashes)
Close
Hashes for yirgachefe-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20aa1424fc8d9a51facbb0b6e3f215ae840e6c0b03da3a60cd52e09a558b4b0b |
|
MD5 | 95759986126e4c87c1b1d45c6169e48b |
|
BLAKE2b-256 | 3d82e3c209124cfa80615c4787a74fd333e36eef8b61f6224006073ec19afc43 |