Skip to content

Commit

Permalink
[AI-5] pip install unixlog
Browse files Browse the repository at this point in the history
  • Loading branch information
raahoolkumeriya committed Sep 13, 2021
1 parent 530bea0 commit 328f15a
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 676 deletions.
693 changes: 19 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions README.md
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'```
6 changes: 6 additions & 0 deletions pyproject.toml
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"
24 changes: 24 additions & 0 deletions setup.cfg
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 added tests/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions tests/test_unixlog.py
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)
11 changes: 11 additions & 0 deletions unixlog/__init__.py
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]
79 changes: 79 additions & 0 deletions unixlog/ulog.py
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

0 comments on commit 328f15a

Please sign in to comment.