Skip to main content

A package to ease log sending to Statuscope

Project description

python-package

Source code of the Python package that is on PyPI

Install & Update

sudo pip3 install --upgrade statuscope

Example

Here is a sample use of the package.

import argparse
import time
import sys
import random

from statuscope.logger import Logger
from statuscope.logger import LoggerConfig

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Sends logs to Statuscope.io')
    parser.add_argument('-t',
                        '--token',
                        help='API token or task-specific token',
                        required=True)
    parser.add_argument('-i',
                        '--task_id',
                        help='Task ID',
                        required=True)
    args = parser.parse_args()

    # Create a logger configuration object and enable logs
    log_config = LoggerConfig()
    log_config.enable_logs()

    log_sender = Logger(args.token, args.task_id, log_config)
    log_sender.start()

    # We'll generate some silly log messages because test data is usually so boring
    objects = [ 'plane', 'bike', 'book', 'icecream', 'dog' ]
    colors = [ 'yellow', 'green', 'red', 'black', 'pink', 'white' ]
    severities = [ 'debug', 'info', 'warning', 'error', 'alert' ]

    counter = 0
    while True:
        counter = counter + 1

        try:
            time.sleep(1)

            severity = random.choice(severities)
            color = random.choice(colors)
            object = random.choice(objects)

            if severity == 'debug':
                log_sender.debug("Log %s: I have a %s %s" % (counter, color, object))

            elif severity == 'info':
                log_sender.info("Log %s: I have a %s %s" % (counter, color, object))

            elif severity == 'warning':
                log_sender.warn("Log %s: I have a %s %s" % (counter, color, object))

            elif severity == 'error':
                log_sender.error("Log %s: I have a %s %s" % (counter, color, object))

            elif severity == 'alert':
                log_sender.alert("Log %s: I have a %s %s" % (counter, color, object))


        except KeyboardInterrupt:
            print("Ctrl-C received, exiting...")
            log_sender.flush()
            try:
                log_sender.join()
            except Exception as e:
                print(str(e))
            sys.exit()

Then to update a log task,

python3 test.py --token cfa0d2ed --task_id QbZJjD2u3uzFvTYAM

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

statuscope-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

statuscope-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file statuscope-0.1.0.tar.gz.

File metadata

  • Download URL: statuscope-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for statuscope-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa91f44803cbc6bae49afe0f79945d3b1c378bda9448504ab4fd4397730a855a
MD5 29b418830729525d0d4b015bb830171f
BLAKE2b-256 b27daf9667c3af949e89f495d7949d29fec0c1c6a4532351bb342f9f89bc22f7

See more details on using hashes here.

File details

Details for the file statuscope-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: statuscope-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for statuscope-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bc00d8e365da9b892f3b64ddfa186c324c24c0f82232c4cf1194b7d8ce51563
MD5 c293c88de5eb35103abe93952ed86821
BLAKE2b-256 bfa2989f1a308251a6a81a6078b373cc2aa4ef545715b39f50a7ee436a1c16bf

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