Skip to content

Commit

Permalink
2.5.0: disable the print of debug level logs (#27)
Browse files Browse the repository at this point in the history
* Enhanced import

* Added pretty_print method

* Updated readme

* circleCI pipelines (#17)

* 2.2.3 - Enhanced import (#13)

* Update requirements_dev.txt

Updated bleach library to version 3.1.2

* Bump bleach from 3.1.2 to 3.1.4 (#15)

Bumps [bleach](https://github.com/mozilla/bleach) from 3.1.2 to 3.1.4.
- [Release notes](https://github.com/mozilla/bleach/releases)
- [Changelog](https://github.com/mozilla/bleach/blob/master/CHANGES)
- [Commits](mozilla/bleach@v3.1.2...v3.1.4)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* 2.3.0 - added pretty_print method (#16)

* Enhanced import

* Added pretty_print method

* Updated readme

* 2.3.0 - added pretty_print method

* Add .circleci/config.yml

* [flake8] code refactory

* [flake8, unittest] code refactory

* [isort, flake8, test_code] pipelines

* updated code versione for tag test

* deploy conditions

* deploy conditions

* deploy conditions

* deploy conditions

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [flake8] fixed W292 error

* fixed stuffs

* fixed stuffs

* updated version

* v2.4.0: circleci

* v2.4.1: circleci

* 2.4.2: circleci integration

* Disable log level debug print optionally

* 2.5.0: optional debug logs print

* fixed urllib3 version

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
mastrobirraio and dependabot[bot] authored Jul 5, 2021
1 parent eff2e94 commit 736fd78
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ You can log a message and exit the program defining optionally and error code.
Logthon.log_and_exit_with_code('This is a message')
```

## Disable debug level log printing
```
logthon = Logthon(debug=False)
logthon.debug('This is a debug log')
# Nothing printed
```

If you want to define log level, you need to import level you want
```
from logthon.logthon import INFO_LEVEL
Expand Down
8 changes: 5 additions & 3 deletions logthon/logthon.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@

class Logthon:

def __init__(self, save_log=False, filename='logthon.log', module_name=None):
def __init__(self, save_log=False, filename='logthon.log', module_name=None, debug=True):
"""Set the format global variable as class attribute"""
self.__filename = filename
self.__save_log = save_log
self.__module_name = module_name
self.__show_debug_logs = debug
self.__set_format()

def __set_format(self):
Expand Down Expand Up @@ -143,8 +144,9 @@ def debug(self, message):
:param message: the message to log
"""
message = self.__compose_message(DEBUG_LEVEL, message)
print(self.__compose_output(LOG_LEVELS[DEBUG_LEVEL], message))
if self.__show_debug_logs:
message = self.__compose_message(DEBUG_LEVEL, message)
print(self.__compose_output(LOG_LEVELS[DEBUG_LEVEL], message))

def log_and_exit_with_code(self, message, level=CRITICAL_LEVEL, error_code=1):
"""Print a log using level defined by user and exit program with error code defined by user
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ requests-toolbelt==0.9.1
six==1.12.0
tqdm==4.32.2
twine==1.13.0
urllib3==1.26.5
urllib3==1.25.11
wcwidth==0.1.7
webencodings==0.5.1
zipp==0.5.2
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def read_file(path):

setup(
name=NAME,
version='2.4.2',
version='2.5.0',
author='Giuseppe "mastrobirraio" Matranga',
author_email='[email protected]',
maintainer='Giuseppe "mastrobirraio" Matranga',
Expand All @@ -56,6 +56,8 @@ def read_file(path):
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Terminals',
Expand Down

0 comments on commit 736fd78

Please sign in to comment.