Skip to content

Commit

Permalink
init code
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnm1 committed Aug 22, 2022
1 parent 2b40674 commit f15e53f
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
dist
logger_rewrite.egg-info
logult.egg-info
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
Easy way to log everything
### Install
```bash
pip install logger_rewrite
pip install logult
```

### Use
<!--
![](assets/hello.png)
-->
<div align=center>
<img src="assets/hello.png" width="500" height="100" />
</div>
```
from logult import setup_log
logger= setup_log(save_dir='saved', name_exp='info.log')
logger.info('Hello')
```
Binary file removed assets/hello.png
Binary file not shown.
17 changes: 0 additions & 17 deletions logger_rewrite/__init__.py

This file was deleted.

Binary file removed logger_rewrite/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed logger_rewrite/__pycache__/logger.cpython-36.pyc
Binary file not shown.
Binary file removed logger_rewrite/__pycache__/utils.cpython-36.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions logult/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
from pathlib import Path
from logult.logger import setup_logging


def setup_log(save_dir='./', name_exp='info.log'):
save_dir = Path(save_dir)
save_dir.mkdir(parents=True, exist_ok=True)
setup_logging(save_dir, exp_name=name_exp)
logger = get_logger()
return logger


def get_logger():
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
return logger
Binary file added logult/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
File renamed without changes.
Binary file added logult/__pycache__/logger.cpython-36.pyc
Binary file not shown.
File renamed without changes.
Binary file added logult/__pycache__/utils.cpython-36.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions logger_rewrite/logger.py → logult/logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
import logging.config
from logger_rewrite.utils import Cfg
from logult.utils import Cfg


def setup_logging(save_dir, default_level=logging.INFO):
def setup_logging(save_dir, exp_name=None, default_level=logging.INFO):
config = Cfg.load_config_from_name()
if exp_name is not None:
config['handlers']['info_file_handler']['filename'] = exp_name
for _, handler in config['handlers'].items():
if 'filename' in handler:
handler['filename'] = str(save_dir / handler['filename'])
Expand Down
2 changes: 1 addition & 1 deletion logger_rewrite/utils.py → logult/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def download_config(id):
url = 'https://raw.githubusercontent.com/cuongngm/logger_rewrite/why/config/{}'.format(id)
url = 'https://raw.githubusercontent.com/cuongngm/logult/why/config/{}'.format(id)
r = requests.get(url)
config = r.text
return config
Expand Down
1 change: 1 addition & 0 deletions saved/info.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[2022-06-29 17:55:15,655 - train - INFO] - Hello world
[2022-06-30 10:32:20,378 - train - INFO] - Hello
[2022-08-22 14:35:42,759 - train - INFO] - abc
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
long_description = fh.read()

setuptools.setup(
name="logger_rewrite",
version="0.3",
name="logult",
version="0.1",
author="cuongngm",
author_email="[email protected]",
description="log scripts",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/cuongngm/logger_rewrite",
url="https://github.com/cuongngm/logult",
packages=setuptools.find_packages(),
install_requires=['requests'
],
Expand Down

0 comments on commit f15e53f

Please sign in to comment.