GithubHelp home page GithubHelp logo

sdf611097 / py-logger Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 24 KB

Python log tool, such as print colorful text

License: MIT License

Python 63.44% Jupyter Notebook 35.48% Shell 1.08%
logger color-console python

py-logger's Introduction

ctlogger

Log tool can help you see log more efficiently, by colors, prefix with time, show line number and so on.

How to use

Install by pip

pip install ctlogger
pip install --upgrade ctlogger

Use

from ctlogger import logger
logger.yellow('This is a yellow log')

Effects

#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

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, ...)

Like print(), but the log is with color which you specified.

logger.cyan('this', 'is', 'a', 'cyan', 'log')
logger.red(1, 2, 3)

bg_color(arg1, arg2, ...)

Similar to color(), this function is for background color and the font-color will be complementary color.

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.

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.bg_blue')

start(*opts), end()

You can set opts and then below log from print will apply this opts until end() be called.

logger.start('yellow','bold')
print('this is yellow and bold')
logger.end()
print('this is normal log')

by_codes(codeList, arg1, arg2, ...)

You can pass other codes, and try it. Find more codes: ANSI ESCAPE CODE

logger.by_codes(['31','4'], "this is equl to logger.log(['red','underline'], ...)")

show_opts()

Once you forgot which option can be use, you can call this function to see all options.

logger.show_opts()

debug()

This log will be print only if the env variable VERBOSE be set.

logger.debug('shows only when', 'VERBOSE', 'been', 'set')

print_line_info(arg1, arg2...) print_stack()

def bar():
    print_line_info('1','2') # <YOUR_FILE_NAME>:12/bar 1 2
    print_stack()
    #<YOUR_FILE_NAME>:13/bar logger.printStack()
    #<YOUR_FILE_NAME>:18/foo bar()
    #<YOUR_FILE_NAME>:19/<module> foo()
    #...
def foo():
    bar()
foo()

Notify

slack, sendgrid is supported

export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/XXX/OOO/QQQ

export SENDGRID_API_KEY=SG.XXXXX.XXXX
export [email protected]
export [email protected],[email protected]
from ctlogger import slack, sendgrid
res = sendgrid.send('SG title', 'SG message')
assert res.status_code == 202
res = slack.send('Slack title', 'Slack message')
assert res.status_code == 200

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.