Skip to main content

A generic logger

Project description

sparen

Create richer more helpful logs using terminal coloring, file saving, graph plotting, and ascii drawing.


Table of contents

 


Install

$ pip3 install sparen

 


Examples

    #----------------------------------------------------------------
    # The simple

    import sparen
    sparen.log("Hello world!")

    '''
        [21:24:31] demo.py:main(189): Hello world!
    '''
    #----------------------------------------------------------------
    # Save to log file
    sparen.log.setLogFile("application.log")


    #----------------------------------------------------------------
    # Color output
    #   Note: Color filters are only applied if the output device is a console

    sparen.log.addLogFilters("error:red,warning:yellow,except:red:blink")
    sparen.log("Error: This will be red")
    sparen.log("Warning: This will be yellow")

    try:
        thisisanerror
    except Exception as e:
        sparen.log("Exception: This will be red and flashing\n", e)

    '''
        [21:24:31] demo.py:main(202): Error: This will be red
        [21:24:31] demo.py:main(203): Warning: This will be yellow
        [21:24:31] demo.py:main(208): Exception: This will be red and flashing
         [EXCEPTION] name 'thisisanerror' is not defined
          > demo.py(206)::main() thisisanerror
    '''

    #----------------------------------------------------------------
    # Format interval
    #       $s  - Seconds
    #       $S  - Seconds with leading zero
    #       $m  - Minutes
    #       $M  - Minutes with leading zero
    #       $h  - Hours
    #       $H  - Hours with leading zero
    #       $d  - Days
    #       $D  - Days with leading zero
    #       $y  - Years
    #       $Y  - Years with leading zero
    #       $f  - Decimal
    #       $F  - Decimal with trailing zeros
    #       $+_ - Show full value

    seconds = 1234567

    sparen.log(sparen.formatInterval(seconds, "$+H:$M:$S"))
    '''
        [21:24:31] demo.py:main(65): 342:56:07
    '''

    sparen.log(sparen.formatInterval(seconds, "$d days, $h hours, $m minutes, $s seconds"))
    '''
        [21:24:31] demo.py:main(64): 14 days, 6 days, 56 minutes, 7 seconds
    '''

    #----------------------------------------------------------------
    # Graph plotting

    data = np.sin(np.linspace(-np.pi * 3, np.pi * 3, 200)) * 10
    sparen.log('PLOT\r\n', sparen.plotArray(data))

    '''
        [21:24:31] demo.py:main(215): PLOT
         10 :                 ...                    ....                   ....
          9 :               ..   .                  .   ..                 ..  ..
          7 :               .     ..               .     ..               .     ..
          5 :              .       .              .       .              .       ..
          3 :             .         .            ..        .            ..        .
          1 :            ..         ..           .         ..           .          .
          0 : .          .           .          .           .          .
         -2 : ..        .             .        .             .        ..
         -4 :  ..      ..             ..      ..             ..       .
         -6 :   .     ..               ..    ..               ..     .
         -8 :    ..  ..                 ..  ..                 ..  ..
        -10 :     ....                   ....                   ....
            ------------------------------------------------------------------------
                    10^       20^       30^       40^       50^       60^       70^
    '''

    #----------------------------------------------------------------
    # Canvas drawing 1

    canv = sparen.Canvas(width=80, height=25, charset=2)

    canv.line(2, 2, 40, 2)
    canv.line(77, 2, 77, 12)

    canv.rect(4, 4, 20, 10)
    canv.line(5, 5, 19, 9)

    canv.fillRect(25, 6, 45, 14)

    canv.circle(60, 6, 5)
    canv.arc(60, 6, 5, 0, 180, '*')

    canv.text(60, 6, "2")

    canv.rect(10, 15, 50, 23)
    canv.textBox(11, 15, 49, 23, 'This\tis a lot of text just to see how well it fits in to the'
                                +' specified box, I could go on and on, and I will, because the'
                                +' point here is to make a really long string and not to not'
                                +' freak out people that do not like to see a lot of text.')

    canv.rect(55, 15, 79, 23)
    canv.textBox(55, 15, 79, 23, 'ThisWordIsJustTooLongToFitOnOneLineAndMustBeForcefullySplit.\n'
                                +' So \n be \n it.')

    sparen.log("Canvas drawing 1\n", canv)

    '''
        [21:24:31] demo.py:main(330): Canvas drawing 1
                                                                    ·
          ═══════════════════════════════════════              ··· · · ···           ║
                                                             ·             ·         ║
            ╔═══════════════╗                               ·               ·        ║
            ║····           ║                              ·                 ·       ║
            ║    ····       ║    ████████████████████     ·*        2        **      ║
            ║        ···    ║    ████████████████████      *                 *       ║
            ║           ····║    ████████████████████       *               *        ║
            ║              ·║    ████████████████████        *             *         ║
            ╚═══════════════╝    ████████████████████          *** * * ***           ║
                                 ████████████████████               *                ║
                                 ████████████████████                                ║
                                 ████████████████████

                ╔═══════════════════════════════════════╗    ╔═══════════════════════╗
                ║ This is a lot of text just to see how ║    ║ThisWordIsJustTooLongTo║
                ║ well it fits in to the specified box, ║    ║FitOnOneLineAndMustBeFo║
                ║   I could go on and on, and I will,   ║    ║    rcefullySplit.     ║
                ║  because the point here is to make a  ║    ║          So           ║
                ║   really long string and not to not   ║    ║          be           ║
                ║ freak out people that do not like to  ║    ║          it.          ║
                ║          see a lot of text.           ║    ║                       ║
                ╚═══════════════════════════════════════╝    ╚═══════════════════════╝
    '''

    #----------------------------------------------------------------
    # Canvas drawing 2

    canv = sparen.Canvas(width=80, height=25, charset=1)

    canv.rect(4, 4, 20, 10)

    canv.line(2, 6, 25, 6)
    canv.line(4, 8, 20, 8)

    canv.line(10, 2, 10, 12)
    canv.line(16, 4, 16, 10)

    canv.rect(44, 4, 60, 10)
    canv.line(42, 4, 65, 4)
    canv.line(42, 10, 68, 10)

    canv.rect(24, 14, 40, 20)
    canv.line(24, 12, 24, 22)
    canv.line(40, 12, 40, 24)

    canv.rect(45, 14, 65, 20)
    canv.rect(50, 16, 70, 22)
    canv.rect(55, 18, 75, 24)

    canv.rect(2, 14, 10, 18)
    canv.rect(10, 14, 18, 18)
    canv.rect(2, 18, 10, 22)
    canv.rect(10, 18, 18, 22)

    sparen.log("Canvas drawing 2\n", canv)

    '''
        [21:24:31] demo.py:main(330): Canvas drawing 2



            ┌─────┼─────┬───┐                     ──┬───────────────┬─────
            │     │     │   │                       │               │
          ──┼─────┼─────┼───┼─────                  │               │
            │     │     │   │                       │               │
            ├─────┼─────┼───┤                       │               │
            │     │     │   │                       │               │
            └─────┼─────┴───┘                     ──┴───────────────┴────────

                  │             │               │
                                │               │
          ┌───────┬───────┐     ├───────────────┤    ┌───────────────────┐
          │       │       │     │               │    │                   │
          │       │       │     │               │    │    ┌──────────────┼────┐
          │       │       │     │               │    │    │              │    │
          ├───────┼───────┤     │               │    │    │    ┌─────────┼────┼────┐
          │       │       │     │               │    │    │    │         │    │    │
          │       │       │     ├───────────────┤    └────┼────┼─────────┘    │    │
          │       │       │     │               │         │    │              │    │
          └───────┴───────┘     │               │         └────┼──────────────┘    │
                                                │              │                   │
                                                │              └───────────────────┘
    '''

 


References

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sparen-0.2.3-py2.py3-none-any.whl (12.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sparen-0.2.3-py2.py3-none-any.whl.

File metadata

  • Download URL: sparen-0.2.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.5

File hashes

Hashes for sparen-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5fa58e45691c00410d8ac40caf9f4d76f0dc02e4567406f968a4c4b108b85ff4
MD5 68f5896d8c92b8352792aa77ff6c14c5
BLAKE2b-256 d2ec1525051dadcd52039b796b37067480e31f7d4a69e0396af5591105b709cb

See more details on using hashes here.

Supported by

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