Skip to main content

Python Logging based on blockchain

Project description

Plogchain

Tests Status Dependencies license Web page

Python Logging based on blockchain.

Messages get chained

The current log line contains the signature of the previous line with your secret.

  • detect lines deletion
  • detect logs tampering

Philosophy

The package is intended to be a lightweight util for generating incorruptible logs.

For this pupose we rely as much as possible on standard packages.

Usage

Install

pip install plogchain

Init once in main

import ChainedLogger

# Obtained after the -vvv option of the program
verbosity = 3
theSecret = ChainedLogger.generateSecret()
ChainedLogger.init(verbosity, theSecret)

Use everywhere with python logging module

import logging

logging.debug("My message")
logging.info("Some information")

Check your logs integrity afterwards

import ChainedLogger

aLogChain = [
	"2020-03-30 13:38:00.782|0ec90b9839fdd964|TestChaining.py:20 test_logging_happy_case hello gg",
	"2020-03-30 13:38:00.782|2e3f1b4a7b946fb1|TestChaining.py:21 test_logging_happy_case voila1",
	"2020-03-30 13:38:00.782|10d1ab606618492a|TestChaining.py:22 test_logging_happy_case voila2",
	"2020-03-30 13:38:00.782|805757e144f4e385|TestChaining.py:23 test_logging_happy_case voila5",
	"2020-03-30 13:38:00.782|3bda90b5af77d3fe|TestChaining.py:24 test_logging_happy_case voila4"
]
isValid = ChainedLogger.verify(aLogChain, theSecret)

Apply you own logging format (WIP)

The package is suitable for server logging which context changes from one transaction to another. Here is an example of setting contextual information throughout the lifecycle of a server:

# Static formatting at program startup...
ChainedLogger.setFormat(
	# Standard python logging fields
	timestamp = "%(asctime)s.%(msecs)03d",
	fileLine  = "%(filename)s:%(lineno)d",
	message   = "%(message)s",

	# Custom fields
	processId = <current PID>
)

# ... then dynamic formatting with runtime context.
ChainedLogger.updateFormat(transactionId = <current transactionId>

Contributing

Install

Simply clone and submit pull requests.

Testing

The unit tests are located in the test folder which contains the __main__.py entrypoint.

# Run all
python test

# Get additional options
python test --help

Delivery

Use to the awesome Poetry tool for this purpose:

poetry publish

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

plogchain-0.0.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

plogchain-0.0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file plogchain-0.0.2.tar.gz.

File metadata

  • Download URL: plogchain-0.0.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.6.9 Linux/4.15.0-96-generic

File hashes

Hashes for plogchain-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5de13b870e9d8c1f34307423190fd1aef82b4bb3bf595568f1c909280d3439e5
MD5 d29dadba47853bc04050ed34067e3646
BLAKE2b-256 1097ecc210a237583c27da86832a9861996ac186c52eefc3b1e770def91b6b06

See more details on using hashes here.

File details

Details for the file plogchain-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: plogchain-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.6.9 Linux/4.15.0-96-generic

File hashes

Hashes for plogchain-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d50d195861af8b7c6d00c1aa1775ab480e0925ce371d25500d71cb3822c7246b
MD5 3cb2c8e65417083e1d680d2a39c78e2b
BLAKE2b-256 a44beb407154f5abf44185d2d7d96c5baf69f3036fcc1a805c914862c0615193

See more details on using hashes here.

Supported by

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