From 8045b7c6806e822360e7236594da9828cc16a449 Mon Sep 17 00:00:00 2001 From: ChunTingLin Date: Fri, 9 Mar 2018 20:15:01 +0800 Subject: [PATCH] Fix Readme, and do some modifications --- README.md | 47 +++++---- ctlogger/logger.py | 103 +++++++++--------- ctlogger/test_logger.py | 3 +- demo.ipynb | 155 +++++++++++++++++++++++++++ setup.py | 2 +- test.ipynb | 229 ---------------------------------------- 6 files changed, 236 insertions(+), 303 deletions(-) create mode 100644 demo.ipynb delete mode 100644 test.ipynb diff --git a/README.md b/README.md index 2f0540a..8578fa6 100644 --- a/README.md +++ b/README.md @@ -11,27 +11,33 @@ RESET, BOLD, FAINT, ITALIC, UNDERLINE #COLORS BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE ``` + ## Usages + ### Time prefix Set your environment variable ENABLE_TIME_PREFIX=1, each log from logger will contians time prefix with format [%m-%d %H:%M:%S] + ### color(arg1, arg2, ...) -Usage is just like print(), but the log will with color which you specified. +Like print(), but the log is with color which you specified. ```python logger.cyan('this', 'is', 'a', 'cyan', 'log') logger.red(1, 2, 3) ``` -## bgColor(arg1, arg2, ...) + +## bg_color(arg1, arg2, ...) Simalar to color(), this funciton is for background color and the font-color will be complementary color. ```python -logger.bgBlue('this', 'log', 'is', 'blue', 'and with background color yellow') +logger.bg_blue('this', 'background color blue, and font is yellow') ``` + ### log(optList, arg1, arg2, ...) print log with options(possible options are shown above) and option is case-insensitive. ```python logger.log(['red','Bg_Yellow'], 3,4,5) #print 3,4,5 (with font-color:red, backgroud is yellow) logger.log(['blue', 'Bold'], 'this', 'is', 'a', 'blue-Bold', 'log') -logger.log(['BG_BLUE', 'YELLOW'], 'this', 'is', 'as', 'same', 'as', 'logger.bgBlue') +logger.log(['BG_BLUE', 'YELLOW'], 'this', 'is', 'as', 'same', 'as', 'logger.bg_blue') ``` + ### start(*opts), end() You can set optsm and then below log from print will apply this opts util end() be called. ```python @@ -41,34 +47,35 @@ logger.end() print('this is normal log') ``` -### byCodes(codeList, arg1, arg2, ...) -If you know the code of SGR (Select Graphic Rendition) parameters, you can pass it directly(string list). +### by_codes(codeList, arg1, arg2, ...) +You can pass other codes, and try it. +Find more codes: [ANSI ESCAPE CODE](https://en.wikipedia.org/wiki/ANSI_escape_code) ```python -logger.byCodes(['31','4'], "this is equl to logger.log(['red','underline'], ...)") +logger.by_codes(['31','4'], "this is equl to logger.log(['red','underline'], ...)") ``` -### showOpts() +### show_opts() Once you forgot which option can be use, you can call this function to see all options. ```python -logger.showOpts() +logger.show_opts() ``` ### debug() -This log will be print only if the env variable VERBOSE been set. +This log will be print only if the env variable VERBOSE be set. ```python logger.debug('shows only when', 'VERBOSE', 'been', 'set') ``` -### printLineInfo(arg1, arg2...) printStack() +### print_line_info(arg1, arg2...) print_stack() ```python -def test(): - printLineInfo('1','2') # :12/test 1 2 - printStack() - #:13/test logger.printStack() - #:18/a test() - #:19/ a() +def bar(): + print_line_info('1','2') # :12/bar 1 2 + print_stack() + #:13/bar logger.printStack() + #:18/foo bar() + #:19/ foo() #... -def a(): - test() -a() +def foo(): + bar() +foo() ``` diff --git a/ctlogger/logger.py b/ctlogger/logger.py index 9815500..d2c4abd 100644 --- a/ctlogger/logger.py +++ b/ctlogger/logger.py @@ -15,7 +15,7 @@ time_format = '[%m-%d %H:%M:%S]' END = '\x1b[0m' -_bgColors = { +__bgColors = { 'BG_BLACK': '40', 'BG_RED': '41', 'BG_GREEN': '42', @@ -26,7 +26,7 @@ 'BG_WHITE': '47', } -_effects = { +__effects = { 'RESET': '0', # all attributes off 'BOLD': '1', # Bold or increased intensity 'FAINT': '2', # Faint (decreased intensity), Not widely supported. @@ -34,7 +34,7 @@ 'UNDERLINE': '4', } -_colors = { +__colors = { 'BLACK': '30', 'RED': '31', 'GREEN': '32', @@ -45,7 +45,7 @@ 'WHITE': '37', } -_fontColorForBGs = { +__fontColorForBGs = { 'BG_BLACK': 'WHITE', 'BG_RED': 'CYAN', 'BG_GREEN': 'MAGENTA', @@ -56,14 +56,14 @@ 'BG_WHITE': 'BLACK', } -_CODE_DICT = {**_bgColors, **_effects, **_colors} +__CODE_DICT = {**__bgColors, **__effects, **__colors} def get_all_options(): - return _CODE_DICT.keys() + return __CODE_DICT.keys() -def _transform_codes(codes): +def __transform_codes(codes): return '\x1b[' + ';'.join(codes) + 'm' @@ -72,7 +72,7 @@ def by_codes(codes, *args, **kwargs): This is core function """ arguments = list(args) - arguments.insert(0, _transform_codes(codes)) + arguments.insert(0, __transform_codes(codes)) if ENABLE_TIME_PREFIX: arguments.insert(0, time.strftime(time_format)) @@ -80,29 +80,29 @@ def by_codes(codes, *args, **kwargs): print(*arguments, **kwargs) -def _show(title, d): +def __show(title, d): cyan(title) italic(', '.join(d.keys())) def show_opts(): """ - BG_COLORS + BG__colors BG_BLACK, BG_RED, BG_GREEN, BG_YELLOW, BG_BLUE, BG_MAGENTA, BG_CYAN, BG_WHITE EFFECTS RESET, BOLD, FAINT, ITALIC, UNDERLINE COLORS BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE """ - _show('BG_COLORS', _bgColors) - _show('EFFECTS', _effects) - _show('COLORS', _colors) + __show('BG__colors', __bgColors) + __show('EFFECTS', __effects) + __show('COLORS', __colors) -def _opts_to_codes(opts): +def __opts_to_codes(opts): opts_upper = [opt.upper() for opt in opts] try: - codes = [_CODE_DICT[opt] for opt in opts_upper] + codes = [__CODE_DICT[opt] for opt in opts_upper] return codes except KeyError: opts.insert(0, 'Unexpected options:') @@ -112,7 +112,7 @@ def _opts_to_codes(opts): def log(opts, *args): - codes = _opts_to_codes(opts) + codes = __opts_to_codes(opts) if codes: by_codes(codes, *args) @@ -126,9 +126,9 @@ def print_line_info(*args, **kwargs): (filename, line_number, function_name, _, _) = inspect.getframeinfo(previous_frame) line_info = filename + ':' + str(line_number) + '/' + function_name if ENABLE_LINE_INFO_TO_STDERR: - by_codes([_colors['RED']], line_info, *args, file=stderr) + by_codes([__colors['RED']], line_info, *args, file=stderr) else: - by_codes([_colors['RED']], line_info, *args) + by_codes([__colors['RED']], line_info, *args) def print_stack(): @@ -142,57 +142,58 @@ def debug(opts, *args): log(opts, *args) -def _one_opt(opt): +def __one_opt(opt): return lambda *args: log([opt], *args) -def _bg_color_shorthand(bg_color): +def __bg_color_shorthand(bg_color): def with_bg_color(*args): try: - log([bg_color, _fontColorForBGs[bg_color.upper()]], *args) + log([bg_color, __fontColorForBGs[bg_color.upper()]], *args) except KeyError: - _show('BG_COLORS', _bgColors) + __show('BG__colors', __bgColors) return with_bg_color def start(*opts): - codes = _opts_to_codes(opts) - print(_transform_codes(codes), end='') + codes = __opts_to_codes(opts) + print(__transform_codes(codes), end='') def end(): # Once start with bg color # Although using RESET to clear bgColor, but the spaces at the end still remain 1 line # Seems there a bug on osx? - print(_transform_codes(['21', '22', '23', '24', _effects['RESET']]), end='') - - -black = _one_opt('black') -red = _one_opt('red') -green = _one_opt('green') -yellow = _one_opt('yellow') -blue = _one_opt('blue') -magenta = _one_opt('magenta') -cyan = _one_opt('cyan') -white = _one_opt('white') - -bold = _one_opt('bold') -faint = _one_opt('faint') -italic = _one_opt('italic') -underline = _one_opt('underline') - -bgBlack = _bg_color_shorthand('bg_black') -bgRed = _bg_color_shorthand('bg_red') -bgGreen = _bg_color_shorthand('bg_green') -bgYellow = _bg_color_shorthand('bg_yellow') -bgBlue = _bg_color_shorthand('bg_blue') -bgMagenta = _bg_color_shorthand('bg_magenta') -bgCyan = _bg_color_shorthand('bg_cyan') -bgWhite = _bg_color_shorthand('bg_white') + print(__transform_codes(['21', '22', '23', '24', __effects['RESET']]), end='') + + +black = __one_opt('black') +red = __one_opt('red') +green = __one_opt('green') +yellow = __one_opt('yellow') +blue = __one_opt('blue') +magenta = __one_opt('magenta') +cyan = __one_opt('cyan') +white = __one_opt('white') + +bold = __one_opt('bold') +faint = __one_opt('faint') +italic = __one_opt('italic') +underline = __one_opt('underline') + +#below are functions so they should be snake_case +bg_black = __bg_color_shorthand('bg_black') +bg_red = __bg_color_shorthand('bg_red') +bg_green = __bg_color_shorthand('bg_green') +bg_yellow = __bg_color_shorthand('bg_yellow') +bg_blue = __bg_color_shorthand('bg_blue') +bg_magenta = __bg_color_shorthand('bg_magenta') +bg_cyan = __bg_color_shorthand('bg_cyan') +bg_white = __bg_color_shorthand('bg_white') if __name__ == '__main__': - by_codes([_colors['RED'], _effects['ITALIC'], _bgColors['BG_GREEN']], 1, 2, 3) + by_codes([__colors['RED'], __effects['ITALIC'], __bgColors['BG_GREEN']], 1, 2, 3) log(['red', 'Bg_Yellow', 'wrongOpt'], 3, 4, 5) debug(['BG_CYAN'], 'this is debug msg') @@ -214,7 +215,7 @@ def a(): green(123, 'abc') cyan('aa') - bgYellow('log with bg yellow') + bg_yellow('log with bg yellow') print('start', 'italic blue bg_green') start('italic', 'blue', 'bg_green') diff --git a/ctlogger/test_logger.py b/ctlogger/test_logger.py index 8d3b174..17270bc 100644 --- a/ctlogger/test_logger.py +++ b/ctlogger/test_logger.py @@ -4,7 +4,7 @@ def test_print_green_color(capsys): # arrange msg = 'Hi' - expect_colored_msg = '\x1b[32m %s \x1b[0m\n' % msg + expect_colored_msg = '\x1b[32m {} \x1b[0m\n'.format(msg) # action logger.green(msg) @@ -12,4 +12,3 @@ def test_print_green_color(capsys): # assert out, err = capsys.readouterr() assert out == expect_colored_msg - diff --git a/demo.ipynb b/demo.ipynb new file mode 100644 index 0000000..a5456a6 --- /dev/null +++ b/demo.ipynb @@ -0,0 +1,155 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from ctlogger import logger" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ### color(arg1, arg2, ...)\n", + "# Using is just like print(), but the log will with color which you specified.\n", + "\n", + "logger.cyan('this', 'is', 'a', 'cyan', 'log')\n", + "logger.red(1, 2, 3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ## bg_color(arg1, arg2, ...)\n", + "# Simalar to color(), this funciton is for background color and the font-color will be complementary color.\n", + "\n", + "logger.bg_blue('this', 'background color blue, and font is yellow')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ### log(optList, arg1, arg2, ...)\n", + "# print log with options(possible options are shown above) and option is case-insensitive.\n", + "\n", + "logger.log(['red','Bg_Yellow'], 3,4,5) #print 3,4,5 (with font-color:red, backgroud is yellow)\n", + "logger.log(['blue', 'Bold'], 'this', 'is', 'a', 'blue-Bold', 'log')\n", + "logger.log(['BG_BLUE', 'YELLOW'], 'this', 'is', 'as', 'same', 'as', 'logger.bg_blue')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ### start(*opts), end()\n", + "# You can set optsm and then below log from print will apply this opts util end() be called.\n", + "\n", + "logger.start('yellow','bold')\n", + "print('this is yellow and bold')\n", + "logger.end()\n", + "print('this is normal log')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ### by_codes(codeList, arg1, arg2, ...)\n", + "# You can pass other codes, and try it.\n", + "# Find more codes: [ANSI ESCAPE CODE](https://en.wikipedia.org/wiki/ANSI_escape_code)\n", + "\n", + "logger.by_codes(['31','4'], \"this is equl to logger.log(['red','underline'], ...)\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# ### show_opts()\n", + "# Once you forgot which option can be use, you can call this function to see all options.\n", + "\n", + "logger.show_opts()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# ### debug()\n", + "# This log will be print only if the env variable VERBOSE be set.\n", + "\n", + "logger.debug('shows only when', 'VERBOSE', 'been', 'set')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "### print_line_info(arg1, arg2...) print_stack()\n", + "def bar():\n", + " logger.print_line_info('1','2') # :12/bar 1 2 \n", + " logger.print_stack()\n", + " #:13/bar logger.printStack()\n", + " #:18/foo bar()\n", + " #:19/ foo()\n", + " #...\n", + "def foo():\n", + " bar()\n", + "foo()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/setup.py b/setup.py index be7aa5c..6594802 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = 'ctlogger', packages = ['ctlogger'], - version = '0.0.1', + version = '0.0.2', description = 'A python log utils', author = 'ChunTing Lin', author_email = 'sdf611097@gmail.com', diff --git a/test.ipynb b/test.ipynb deleted file mode 100644 index e35310f..0000000 --- a/test.ipynb +++ /dev/null @@ -1,229 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[31;43m 123 456 \u001b[0m\n", - "123\n" - ] - } - ], - "source": [ - "print('\\x1b[31;43m',123, 456,'\\x1b[0m')\n", - "print('123')" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "a\n", - "b\n" - ] - }, - { - "ename": "KeyError", - "evalue": "'c'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m'123'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'c'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m: 'c'" - ] - } - ], - "source": [ - "d={\"a\":1,'b':2}\n", - "for key in d.keys():\n", - " print(key)\n", - "'123'.join(d.keys())\n", - "\n", - "try\n", - "d['c']" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "123\n" - ] - } - ], - "source": [ - "'abc'.upper()\n", - "def abc():\n", - " def cde():\n", - " print(123)\n", - " cde()\n", - "abc()" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[02-04 10:19:04]\n" - ] - } - ], - "source": [ - "import time\n", - "print(time.strftime('[%m-%d %H:%M:%S]'))" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Traceback(filename='', lineno=6, function='', code_context=['hi()\\n'], index=0)\n", - "\n" - ] - } - ], - "source": [ - "import inspect\n", - "def hi():\n", - " previous_frame = inspect.currentframe().f_back\n", - " print(inspect.getframeinfo(previous_frame))\n", - "\n", - "hi()\n", - "print()" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[36m this is a cyan log \u001b[0m\n", - "\u001b[31m 1 2 3 \u001b[0m\n", - "\u001b[44;33m this log is blue and with background color yellow \u001b[0m\n", - "\u001b[31;43m 3 4 5 \u001b[0m\n", - "\u001b[34;1m this is a blue-Bold log \u001b[0m\n", - "\u001b[44;33m this is as same as logger.bgBlue \u001b[0m\n", - "\u001b[36m BG_COLORS \u001b[0m\n", - "\u001b[3m BG_BLACK, BG_RED, BG_GREEN, BG_YELLOW, BG_BLUE, BG_MAGENTA, BG_CYAN, BG_WHITE \u001b[0m\n", - "\u001b[36m EFFECTS \u001b[0m\n", - "\u001b[3m RESET, BOLD, FAINT, ITALIC, UNDERLINE \u001b[0m\n", - "\u001b[36m COLORS \u001b[0m\n", - "\u001b[3m BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE \u001b[0m\n", - "\u001b[31;4m this is equl to logger.log(['red','underline'], ...) \u001b[0m\n", - "\u001b[31m :12/test 1 2 \u001b[0m\n", - ":13/test logger.printStack()\n", - ":18/a test()\n", - ":19/ a()\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2862/run_code exec(code_obj,self.user_global_ns,self.user_ns)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2802/run_ast_nodes ifself.run_code(code,result):\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2698/run_cell interactivity=interactivity,compiler=compiler,result=result)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel\\zmqshell.py:533/run_cell returnsuper(ZMQInteractiveShell,self).run_cell(*args,**kwargs)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel\\ipkernel.py:196/do_execute res=shell.run_cell(code,store_history=store_history,silent=silent)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:399/execute_request user_expressions,allow_stdin)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:235/dispatch_shell handler(stream,idents,msg)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:283/dispatcher returnself.dispatch_shell(stream,msg)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\tornado\\stack_context.py:277/null_wrapper returnfn(*args,**kwargs)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py:414/_run_callback callback(*args,**kwargs)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py:472/_handle_recv self._run_callback(callback,msg)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\zmqstream.py:440/_handle_events self._handle_recv()\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\tornado\\stack_context.py:277/null_wrapper returnfn(*args,**kwargs)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\tornado\\ioloop.py:888/start handler_func(fd_obj,events)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\zmq\\eventloop\\ioloop.py:177/start super(ZMQIOLoop,self).start()\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelapp.py:477/start ioloop.IOLoop.instance().start()\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\traitlets\\config\\application.py:658/launch_instance app.start()\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:16/ app.launch_new_instance()\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\runpy.py:85/_run_code exec(code,run_globals)\n", - "C:\\Users\\ChunTing\\Anaconda3\\lib\\runpy.py:193/_run_module_as_main \"__main__\",mod_spec)\n", - "\u001b[33;1mthis is yellow and bold\n", - "\u001b[21;22;23;24;0mthis is normal log\n" - ] - } - ], - "source": [ - "\n", - "from ctlogger import logger\n", - "logger.cyan('this', 'is', 'a', 'cyan', 'log')\n", - "logger.red(1, 2, 3)\n", - "logger.bgBlue('this', 'log', 'is', 'blue', 'and with background color yellow')\n", - "logger.log(['red','Bg_Yellow'], 3,4,5) #print 3,4,5 (with font-color:red, backgroud is yellow)\n", - "logger.log(['blue', 'Bold'], 'this', 'is', 'a', 'blue-Bold', 'log')\n", - "logger.log(['BG_BLUE', 'YELLOW'], 'this', 'is', 'as', 'same', 'as', 'logger.bgBlue')\n", - "logger.showOpts()\n", - "logger.byCodes(['31','4'], \"this is equl to logger.log(['red','underline'], ...)\")\n", - "def test():\n", - " logger.printLineInfo('1','2')\n", - " logger.printStack()\n", - " #:13/test logger.printStack()\n", - " #:15/a test()\n", - " #:16/ a()\n", - "def a():\n", - " test()\n", - "a()\n", - "logger.start('yellow','bold')\n", - "print('this is yellow and bold')\n", - "logger.end()\n", - "print('this is normal log')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}