Skip to main content

Classed based logger for Python

Project description

Class Based Logger for Python

Installation

pip install tdlogging

Doc

Configuration File

tdlogger.txt

A config text file for TDLogger

  • exception log exceptions
  • count log count
  • time log time elapsed
  • return log return value
  • exec log all
  • poll whether to poll for tdlogger.txt changes
  • poll_period seconds between each poll

TDLogger.py

TDLogger

Python Class

__init__

Constructor

  • file_path path of tdlogger.txt
  • config custom config in python dict that overrides tdlogger.txt
  • alias a name for your logger

.config()

Get the Logger decorator from its Configuration

ApplyDecorators

Python Function

Parameters

  • target_dir Directory that is affected
  • import_root Python import name of your tdlogger instance
  • var_name Variable name of the TDLogger instance in your file
  • force Whether to ignore applying at the current file level
  • verbose Whether to log changes

DANGEROUS, use with caution
Apply decorators to every python file in the Directory, and also marking the file

RemoveDecorators

Python Function

Parameters

  • target_dir Directory that is affected
  • import_root Python import name of your tdlogger instance
  • var_name Variable name of the TDLogger instance in your file
  • force Apply Changes without confirmation
  • verbose Whether to log changes

DANGEROUS, use with caution
Remove decorators to every python file in the Directory, and also removing the mark headings

Usage

Example

๐Ÿ“ฆexample
โ”ฃ ๐Ÿ“‚cool
โ”ƒ โ”ฃ ๐Ÿ“‚cooler
โ”ƒ โ”ƒ โ”ฃ ๐Ÿ“œsleep.py
โ”ƒ โ”ƒ โ”— ๐Ÿ“œ__init__.py
โ”ƒ โ”ฃ ๐Ÿ“œfib.py
โ”ƒ โ”— ๐Ÿ“œ__init__.py
โ”ฃ ๐Ÿ“œlogger_instance.py
โ”ฃ ๐Ÿ“œplayground.py
โ”ฃ ๐Ÿ“œtdlogger.txt
โ”— ๐Ÿ“œ__init__.py

# example/tdlogger.txt

exception = False
count = False
exec = True
time = False
return = False
poll = False
poll_period = 5
# example/cool/fib.py

class Fib:

    @staticmethod
    def get_n(n):
        a = 0
        b = 1

        if n == 0:
            return a
        elif n == 1:
            return b
        else:
            for i in range(2, n):
                c = a + b
                a = b
                b = c
            return b
# example/cool/cooler/sleep.py

import time

class Sleep:
    @staticmethod
    def sleep(n):
        time.sleep(n)
# example/logger_instance.py

from tdlogging.tdlogger import TDLogger

logger = TDLogger(alias="My Custom Logger").config()
# example/playground.py

from tdlogging.tdlogger import ApplyDecorators, RemoveDecorators

ApplyDecorators(target_dir="cool", import_root="example.logger_instance", var_name="logger", force=True)

for i in range(12):
    from example.cool.cooler.sleep import Sleep
    from example.cool.fib import Fib

    print(Fib.get_n(i))
    Sleep.sleep(1)

RemoveDecorators(target_dir="cool", import_root="example.logger_instance", var_name="logger", force=True)
> python example/playground.py

Added 6 lines to 2 file(s) .
โ”Žโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”’
โ”ƒ    --Method Execution--    โ”ƒ
โ”ƒ Alias: My Custom Logger    โ”ƒ
โ”ƒ Class: Fib                 โ”ƒ
โ”ƒ Method: get_n              โ”ƒ
โ”ƒ Count: 1                   โ”ƒ
โ”ƒ Exec Time: 0.000s          โ”ƒ
โ”ƒ Return Value: 0            โ”ƒ
โ”ƒ Return Type: <class 'int'> โ”ƒ
โ”ƒ Arguments: {               โ”ƒ
โ”ƒ     'n': 0                 โ”ƒ
โ”ƒ }                          โ”ƒ
โ”ƒ                   tdlogger โ”ƒ
โ”–โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”š

0
โ”Žโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”’
โ”ƒ      --Method Execution--       โ”ƒ
โ”ƒ Alias: My Custom Logger         โ”ƒ
โ”ƒ Class: Sleep                    โ”ƒ
โ”ƒ Method: sleep                   โ”ƒ
โ”ƒ Count: 1                        โ”ƒ
โ”ƒ Exec Time: 1.001s               โ”ƒ
โ”ƒ Return Value: None              โ”ƒ
โ”ƒ Return Type: <class 'NoneType'> โ”ƒ
โ”ƒ Arguments: {                    โ”ƒ
โ”ƒ     'n': 1                      โ”ƒ
โ”ƒ }                               โ”ƒ
โ”ƒ                        tdlogger โ”ƒ
โ”–โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”š
3

.
.
.

โ”Žโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”’
โ”ƒ      --Method Execution--       โ”ƒ
โ”ƒ Alias: My Custom Logger         โ”ƒ
โ”ƒ Class: Sleep                    โ”ƒ
โ”ƒ Method: sleep                   โ”ƒ
โ”ƒ Count: 12                       โ”ƒ
โ”ƒ Exec Time: 1.000s               โ”ƒ
โ”ƒ Return Value: None              โ”ƒ
โ”ƒ Return Type: <class 'NoneType'> โ”ƒ
โ”ƒ Arguments: {                    โ”ƒ
โ”ƒ     'n': 1                      โ”ƒ
โ”ƒ }                               โ”ƒ
โ”ƒ                        tdlogger โ”ƒ
โ”–โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”š

Removed 6 lines from 2 file(s) .

Process finished with exit code 0

Change log

[0.0.5] - 2020-04-12

Added

  • ApplyDecorator()
  • RemoveDecorator()

[0.0.4] - 2020-04-02

Fixed unable to install

[0.0.3] - 2020-04-02

Fixed Markdown file

[0.0.2] - 2020-04-02

Added

  • tdprinter.py

Edited

  • tdprinter.py
  • tdlogger.py

[0.0.1] - 2020-04-01

Added

  • tdlogger.py
  • HISTORY.md
  • README.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tdlogging-0.0.6.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tdlogging-0.0.6-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file tdlogging-0.0.6.tar.gz.

File metadata

  • Download URL: tdlogging-0.0.6.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.4

File hashes

Hashes for tdlogging-0.0.6.tar.gz
Algorithm Hash digest
SHA256 b2fca2cb6a8c6650e9c3c297175127d1d574362e7900b21a635eb8105d0f7cd4
MD5 f6a42cb3f2739aa731816b3dc0323463
BLAKE2b-256 bb1b7f20b0c58f86e0e421f7490874562f2da1096ef20592391717c05d8db244

See more details on using hashes here.

File details

Details for the file tdlogging-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: tdlogging-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.4

File hashes

Hashes for tdlogging-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f35efb301a376b4a415df6b393566e028dd2c9134809b2deedd7af73f5315b3e
MD5 6421d0d91201169e9df4f3630843932b
BLAKE2b-256 62a14e1e17951b54161c8a8075c5a0c02d430456171a8a196e97fcc03b360b5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page