Skip to main content

Noodle Logging - The tiny JSON logger for Python 3.x

Noodle Logging is a tiny package aimed at making logging from python applications into JSON easier.

Dependencies

  1. structlog
  2. python-json-logger
  3. six

Installation

pip3 install noodle-logging

Usage Examples

1. Basic logging
from noodle_logging.logger import log

def test():
    log.info("event", some_parameter=12, some_other_parameter="hello")

if __name__ == "__main__":
    test()
Output
{"message": "event", "some_parameter": 12, "some_other_parameter": "hello", "logger": "__main__", "level": "info", "timestamp": "2019-05-28T11:59:14.975823Z"}
2. High level Profiling - Using decorators
import time

from noodle_logging.decorators import profile

@profile
def some_method(*args, **kwargs):
    time.sleep(1)
    print(some_method.__name__, "method in execution with args ", args,
          " and kwargs ", kwargs)
    time.sleep(1)

if __name__ == "__main__":
    some_method(1, 2, 3, a=2, b=3)
Output
{"message": "Function Profiler", "fn_name": "some_method", "fn_id": "2df1335aa93f41438412da6b517a6781", "timestamp_start": 1559044955.3319192, "fn_args": "1,2,3", "fn_kwargs": "{\"a\": 2, \"b\": 3}", "logger": "noodle_logging.decorators", "level": "info", "timestamp": "2019-05-28T12:02:35.332396Z"}
>>> some_method method in execution with args  (1, 2, 3)  and kwargs  {'a': 2, 'b': 3}
{"message": "Function Profiler", "fn_name": "some_method", "fn_id": "2df1335aa93f41438412da6b517a6781", "timestamp_start": 1559044955.3319192, "fn_args": "1,2,3", "fn_kwargs": "{\"a\": 2, \"b\": 3}", "timestamp_end": 1559044957.340735, "exec_time": 2.0088157653808594, "logger": "noodle_logging.decorators", "level": "info", "timestamp": "2019-05-28T12:02:37.340991Z"}
3. Catching (and Logging) an exception - Using decorators
from noodle_logging.decorators import log_exceptions

@log_exceptions
def some_other_method(*args, **kwargs):
    print(some_other_method.__name__, "method in execution with args ",
          args, " and kwargs ", kwargs)
    print(1 / 0)
    # Below line will not be executed.
    print("Execution completed", some_other_method.__name__)

if __name__ == "__main__":
    some_other_method(1, 2, 3, a=2, b=3, c=4)
Output
some_other_method method in execution with args  (1, 2, 3)  and kwargs  {'a': 2, 'b': 3, 'c': 4}
{"message": "Exception Found.", "exception": "Traceback (most recent call last):\n  File \"/Users/askar.ali/Desktop/noodle-logging-original/noodle_logging/decorators.py\", line 48, in wrapper\n    return func(*args, **kwargs)\n  File \"run.py\", line 29, in some_other_method\n    print(1/0)\nZeroDivisionError: division by zero", "fn_args": "1,2,3", "fn_kwargs": "{\"a\": 2, \"b\": 3, \"c\": 4}", "logger": "noodle_logging.decorators", "level": "error", "timestamp": "2019-05-28T12:06:10.188581Z"}
Traceback (most recent call last):
  File "run.py", line 49, in <module>
    some_other_method(1, 2, 3, a=2, b=3, c=4)
  File "/Users/askar.ali/Desktop/noodle-logging-original/noodle_logging/decorators.py", line 48, in wrapper
    return func(*args, **kwargs)
  File "run.py", line 29, in some_other_method
    print(1/0)
ZeroDivisionError: division by zero
4. Profiling + Catching (and Logging) exceptions - Using decorators
from noodle_logging.decorators import profile, log_exceptions

@profile
@log_exceptions
def noodling_around(*args, **kwargs):
    print(noodling_around.__name__, "method in execution with args ",
          args, " and kwargs ", kwargs)
    print(1 / 0)
    # This line will not be executed.
    print("Execution completed", noodling_around.__name__)

if __name__ == "__main__":
    noodling_around(1, 2, 3, a=2, b=3, c=4)
Output
{"message": "Function Profiler", "fn_name": "noodling_around", "fn_id": "9a3e74924b77440c9a5f1fe4c05522e6", "timestamp_start": 1559045360.7205062, "fn_args": "1,2,3", "fn_kwargs": "{\"a\": 2, \"b\": 3, \"c\": 4}", "logger": "noodle_logging.decorators", "level": "info", "timestamp": "2019-05-28T12:09:20.720621Z"}
noodling_around method in execution with args  (1, 2, 3)  and kwargs  {'a': 2, 'b': 3, 'c': 4}
{"message": "Exception Found.", "exception": "Traceback (most recent call last):\n  File \"/Users/askar.ali/Desktop/noodle-logging-original/noodle_logging/decorators.py\", line 48, in wrapper\n    return func(*args, **kwargs)\n  File \"run.py\", line 41, in noodling_around\n    print(1 / 0)\nZeroDivisionError: division by zero", "fn_args": "1,2,3", "fn_kwargs": "{\"a\": 2, \"b\": 3, \"c\": 4}", "logger": "noodle_logging.decorators", "level": "error", "timestamp": "2019-05-28T12:09:20.721559Z"}
Traceback (most recent call last):
  File "run.py", line 50, in <module>
    noodling_around(1, 2, 3, a=2, b=3, c=4)
  File "/Users/askar.ali/Desktop/noodle-logging-original/noodle_logging/decorators.py", line 26, in wrapper
    result = func(*args, **kwargs)
  File "/Users/askar.ali/Desktop/noodle-logging-original/noodle_logging/decorators.py", line 48, in wrapper
    return func(*args, **kwargs)
  File "run.py", line 41, in noodling_around
    print(1 / 0)
ZeroDivisionError: division by zero

Download files

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

Source Distribution

noodle-logging-0.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

noodle_logging-0.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file noodle-logging-0.2.tar.gz.

File metadata

  • Download URL: noodle-logging-0.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for noodle-logging-0.2.tar.gz
Algorithm Hash digest
SHA256 b744cd46a4218a927057ac6edd027ac6ff79438087ea32a3cd9b32d66a038548
MD5 f4c88f583c25682c851f3383d0b34926
BLAKE2b-256 e46f8105e88778b869c0cb41b532f1fc2e54cc41c74ff1bd642d63270d7d536a

See more details on using hashes here.

File details

Details for the file noodle_logging-0.2-py3-none-any.whl.

File metadata

  • Download URL: noodle_logging-0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for noodle_logging-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e73255c00ae84354819ac8c11d9e410e21b4c082a33f18f3656a5c379aff86f
MD5 810071d475803614347f4e85a316b0f0
BLAKE2b-256 57970d9d1b4913ef2793d7aecbd3a527e0fb42249d50a0d3e7c7ca7c783745c9

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3

2 files

This release

0.2 This release

2 files

0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page