Skip to main content

A generic logger

Project description

sparen

Simple logging library supporting terminal coloring, file saving, and graph plot output.


Table of contents

 


Install

$ pip3 install sparen

 


Examples

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

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


    #----------------------------------------------------------------
    # More options

    import json
    import argparse
    import numpy as np

    import sparen
    Log = sparen.Log

    def fun2():
        something = nogood

    def fun1():
        fun2()

    def main():

        Log("sparen version: %s" % sparen.__version__)
        Log(dir(sparen))

        ap = argparse.ArgumentParser(description='Test')
        ap.add_argument('--format', '-f', default='error:red,warning:yellow,except:red', type=str, help='Log format')
        ap.add_argument('--logfile', '-l', default='', type=str, help='Log file')
        _p = vars(ap.parse_args())

        if _p['logfile']:
            Log.setLogFile(_p['logfile'])

        Log("Parameters: " + json.dumps(_p, indent=4, sort_keys=True))

        if _p['format']:
            Log.addLogFilters(_p['format'])

        Log('a', 'b', 'c', 'ok')

        Log("WARNING: Don't do that again")

        Log("ERROR: Bad thing happened")

        try:
            fun1()
        except Exception as e:
            Log('Something went really wrong\n', e)

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

    if __name__ == '__main__':
        main()

Output

    [21:10:12] test.py:main(18): sparen version: 0.1.1

    [21:10:12] test.py:main(19): ['Log', 'Logging', '__author__', '__builtins__', '__cached__', '__company__', '__description__', '__doc__', '__email__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__url__', '__version__', 'datetime', 'functools', 'getframeinfo', 'inspect', 'loadConfig', 'os', 'plotArray', 'print_function', 'sparen', 'stack', 'sys', 'time', 'traceback']

    [21:10:12] test.py:main(29): Parameters: {
        "format": "error:red,warning:yellow,except:red",
        "logfile": ""
    }

    [21:10:12] test.py:main(34): a b c ok

    [21:10:12] test.py:main(36): WARNING: Don't do that again

    [21:10:12] test.py:main(38): ERROR: Bad thing happened

    [21:10:12] test.py:main(43): Something went really wrong
    [EXCEPTION] name 'nogood' is not defined
     > test.py(11)::fun2() something = nogood
     > test.py(14)::fun1() fun2()
     > test.py(41)::main() fun1()

    [21:10:12] test.py:main(45): PLOT
     10 :                 ...                    ....                   ....
      9 :               ..   .                  .   ..                 ..  ..
      7 :               .     ..               .     ..               .     ..
      5 :              .       .              .       .              .       ..
      3 :             .         .            ..        .            ..        .
      1 :            ..         ..           .         ..           .          .
      0 : .          .           .          .           .          .
     -2 : ..        .             .        .             .        ..
     -4 :  ..      ..             ..      ..             ..       .
     -6 :   .     ..               ..    ..               ..     .
     -8 :    ..  ..                 ..  ..                 ..  ..
    -10 :     ....                   ....                   ....
        ------------------------------------------------------------------------
                10^       20^       30^       40^       50^       60^       70^

 


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.1.4-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: sparen-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.10

File hashes

Hashes for sparen-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7398d8479568f4fb09db4374f766ac3b2fa17d0581bea6011c0a508b71b4540f
MD5 2bc3833a50237b34834f22796d0297d4
BLAKE2b-256 5ef785dedc6f61366d9d82105ce4ff2065d0e493313e682f12b465dcc6123abb

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