-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
530bea0
commit 328f15a
Showing
8 changed files
with
188 additions
and
676 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# unixlog | ||
Python utility to print Unix style logging on terminal | ||
A simple unix style logging in color format. Light weight library for Color formating. | ||
|
||
## Features | ||
- Include warning, error, info, debug, success, trace | ||
- Light weight import | ||
- unix style format | ||
|
||
## Installation | ||
```pip install unixlog``` | ||
|
||
## Examples | ||
|
||
```>>> from unixlog import error, warning, info, success, trace, debug | ||
>>> print(error("This error text")) | ||
[ ERROR ] This error text | ||
>>> error("This error text") | ||
'\x1b[91m[ ERROR ] This error text\x1b[0m'``` |
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,6 @@ | ||
[build-system] | ||
requires = [ | ||
"setuptools>=42", | ||
"wheel" | ||
] | ||
build-backend = "setuptools.build_meta" |
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,24 @@ | ||
[metadata] | ||
name = unixlog | ||
version = 0.0.1 | ||
author = Raahool Kumeriya | ||
author_email = rahul.kumeriya@outlook.com | ||
description = Python program prints unix style logging on terminal | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
url = https://github.com/raahoolkumeriya/unixlog | ||
project_urls = | ||
Bug Tracker = https://github.com/raahoolkumeriya/unixlog/issues | ||
classifiers = | ||
Programming Language :: Python :: 3 | ||
License :: OSI Approved :: MIT License | ||
Operating System :: OS Independent | ||
|
||
[options] | ||
package_dir = | ||
= src | ||
packages = find: | ||
python_requires = >=3.0 | ||
|
||
[options.packages.find] | ||
where = src |
Empty file.
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 @@ | ||
from unixlog.ulog import apply_color, info, warning, error, success, debug, trace | ||
import unittest | ||
|
||
|
||
class TestCharts(unittest.TestCase): | ||
def setUp(self): | ||
self.text = "Hello Unix Log utility" | ||
|
||
def test_unixlog_apply_color_function(self): | ||
assert "Hello" in apply_color("info", self.text) | ||
|
||
def test_unixlog_warning_function(self): | ||
assert 'WARNING' in warning(self.text) | ||
|
||
def test_unixlog_info_function(self): | ||
assert 'INFO' in info(self.text) | ||
|
||
def test_unixlog_error_function(self): | ||
assert 'ERROR' in error(self.text) | ||
|
||
def test_unixlog_success_function(self): | ||
assert 'SUCCESS' in success(self.text) | ||
|
||
def test_unixlog_debug_function(self): | ||
assert 'DEBUG' in debug(self.text) | ||
|
||
def test_unixlog_trace_function(self): | ||
assert 'TRACE' in trace(self.text) |
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,11 @@ | ||
from unixlog.ulog import warning, error,\ | ||
info, debug, trace, success, apply_color | ||
|
||
__all__ = [ | ||
info, | ||
error, | ||
warning, | ||
debug, | ||
trace, | ||
success, | ||
apply_color] |
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,79 @@ | ||
from colorama import Fore, Style | ||
from functools import wraps | ||
|
||
|
||
def apply_color(mode, text): | ||
""" | ||
Common function for applying color like unix style | ||
Attributes | ||
---------- | ||
mode (str): string | ||
text (str): string | ||
Returns | ||
------- | ||
str | ||
""" | ||
color_dict = { | ||
'warning': Fore.LIGHTYELLOW_EX, | ||
'error': Fore.LIGHTRED_EX, | ||
'success': Fore.LIGHTGREEN_EX, | ||
'debug': Fore.LIGHTCYAN_EX, | ||
'info': Fore.LIGHTBLUE_EX, | ||
'trace': Fore.LIGHTMAGENTA_EX | ||
} | ||
return color_dict.get(mode) + text + Style.RESET_ALL | ||
|
||
|
||
def center_filler(f): | ||
@wraps(f) | ||
def wrapper(*args): | ||
return apply_color(f.__name__, f'[{f.__name__.upper().center(9)}] ' + args[0]) | ||
return wrapper | ||
|
||
|
||
@center_filler | ||
def warning(text): | ||
""" | ||
Warning Function with Yellow Color texted retrun string | ||
""" | ||
return text | ||
|
||
@center_filler | ||
def error(text): | ||
""" | ||
Error Function with Red Color texted retrun string | ||
""" | ||
return text | ||
|
||
@center_filler | ||
def info(text): | ||
""" | ||
Info Function with Blue Color texted retrun string | ||
""" | ||
return text | ||
|
||
|
||
@center_filler | ||
def success(text): | ||
""" | ||
Success Function with Green Color texted retrun string | ||
""" | ||
return text | ||
|
||
|
||
@center_filler | ||
def debug(text): | ||
""" | ||
Debug Function with Cyan Color texted retrun string | ||
""" | ||
return text | ||
|
||
|
||
@center_filler | ||
def trace(text): | ||
""" | ||
Trace Function with Magenta Color texted retrun string | ||
""" | ||
return text |