samueleishion / logr-py

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logr-py

Log to output to screen/logfiles in a colored format

Example of displayed output

Import

from logr import logr

Config

To provide a specific configuration, import the Logr class and pass in your preferences:

from logr import Logr

logr = Logr(namespace='myapp', verbose=True, save=True, mute=False)

Available configuration values:

Name Default value Update method Description
namespace logr set_namespace() Provides a namespace for all the files created. By default, all the files get saved with the following name format: logs/{namespace}-YYYY-MM-DD-hh:mm:ss.txt. The namespace specifies that part of the file name for easier tracking.
verbose True set_verbose() This includes the timestape and log type for each line printed/outputed.
save True set_save() This tells logr to save the log output into a file. If set to False, logr would output the logs to stdout.
mute False set_mute() This tells logr to stopp from printing/file-logging. For instance, it can log in development, but mute in production, or in at any given time in run-time temporarily.

API

Success

logr.success("string")

Error

logr.error("string")

Warning

logr.warning("string")

Info

logr.info("string")

Test

logr.test("string")

Idle

logr.idle("string")

Data

logr.data("string")

Transaction

logr.transaction("string")

Tick

logr.tick(0.45)
logr.tick(-0.54)
logr.tick("+$0.45")
logr.tick("-$0.54")
logr.tick("+0.45%")
logr.tick("-0.54%")

Stage

logr.stage("Stage")

Live/pause

for filename in files:
  logr.live(f"Loading {filename}...")
logr.pause()

target = 100
blocks = 10
for i in range(target + 1):
  percent = i/target
  done = '█' * round(percent * blocks)
  togo = '░' * round((1 - percent) * blocks)
  logr.live(f'Testing [{done}{togo}] {round(percent*100, 1)}%')
  time.sleep(0.1)
logr.pause()

Table

data = {}
data['header'] = [
    {
        'label': 'First Name',
        'accessor': 'fname',
        'align': 'left'
    },
    {
        'label': 'Last Name',
        'accessor': 'lname'
    },
    {
        'label': 'Age',
        'accessor': 'age',
        'align': 'right'
    }
]

data['rows'] = [
    {
        'fname': 'John',
        'lname': 'Smith',
        'age': '20'
    },
    {
        'fname': 'Katherine',
        'lname': 'Johnson',
        'age': '29'
    },
    {
        'fname': 'Devon',
        'lname': 'Adams',
        'age': '32'
    }
]

logr.table(data, "single")

logr.table(data, "double")

logr.data(data, "dashed") # default

logr.data(data, "dotted")

Skip

logr.skip()

New file

logr.new_file()

About

License:MIT License


Languages

Language:Python 99.5%Language:Makefile 0.5%