Skip to main content

A Python logging handler for sending logs to LogSense

Project description

logsense-logger-python

Provides a set of wrapper classes and method for working with Python and LogSense

Usage

Installation

pip3 install logsense-logger

Wrapping logging

from logsense.handler import LogSenseHandler
from os import getenv
import logging

logsense_token = getenv('LOGSENSE_TOKEN', None)
log = logging.getLogger()
log.addHandler(LogSenseHandler(logsense_token))
log.setLevel(logging.INFO)


class Example:
    def __init__(self):
        self.bar = 42

    def foo(self):
        logging.info("Answer: {}".format(self.bar))


if __name__ == "__main__":
    ex = Example()
    ex.foo()

Now, just run the app, e.g.

LOGSENSE_TOKEN="63da4903-01e9-d1a4-82a8-9cf8cd63b7b5" python sample_logging.py

And your logs should flow to LogSense

Metrics

The package also includes a simple example on how to measure method duration and have ability to track metrics. All that needs to be done is providing LOGSENSE_TOKEN environment variable and than annotating methods that are to be measure with @measure_duration(). For example:

from logsense.metrics import measure_duration, setup_metrics
from os import getenv

logsense_token = getenv('LOGSENSE_TOKEN')
setup_metrics('myapp', logsense_token)


class MyComplexProcess:
    def __init__(self, how_many_times):
        self._how_many_times = how_many_times

    @measure_duration(extracted_params=['a'])
    def foo(self, a):
        x = 0
        for i in range(a*self._how_many_times):
            x = x+1
        return x

Examples

Check the example for actual usage examples

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

logsense-logger-0.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

logsense_logger-0.2.0-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file logsense-logger-0.2.0.tar.gz.

File metadata

  • Download URL: logsense-logger-0.2.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

File hashes

Hashes for logsense-logger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2f59e8bb41e7e0a31bcac6bfb60d4324ceb01401f7322df9cb5c524ccc063c7e
MD5 d3ddc96f43192c91b359229b0e95e3f4
BLAKE2b-256 af9365c01bb5cb684283b3302156ded0b0e961fb48da08718e00ad8f57d69df6

See more details on using hashes here.

File details

Details for the file logsense_logger-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: logsense_logger-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

File hashes

Hashes for logsense_logger-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 df0dab3abcf5d50b6b4155376806d5c3780d60ec645b77feab4d59220277c69b
MD5 0cf8ca468341a81975ba594d12fcef18
BLAKE2b-256 f02dbea6263dfe453775633679aa9453c748f086af907b174fd5a2c7bf6a6cef

See more details on using hashes here.

Supported by

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