Skip to main content

A simple lib for postgres logging

Project description

======
pglogs
======
Save logs records in postgres.
Log record can contain any num of fields.
Logs format in the table:
id SERIAL
data TEXT
{"field1": "value", "field2": "value", "field3": "value"}


# example of use
from pglogs.models import Pg, LogRecord

pg = Pg('pglogs', 'pglogs_user', '127.0.0.1', 'qwerty')
pg.connect()

log = LogRecord(pg)
log.set_field('chef_request', """'{}[[[]dfdfd''']]--pdfdfdfdfd\\SOME HACKER BEEN HERE}'""")
log.set_field('proxy_response', """dfdg'gfgfd'g'dsgd\'gfsdfg\'gdf/dgfd/fdg/f/dgd'\"\\''''""")
log.commit()


# example of use for log Flask requests
from pglogs.models import Pg, LogRecord
from pglogs.utils import pack_request_log
from flask import Flask, request, g

app = Flask(__name__)
pg = Pg('pglogs', 'pglogs_user', '127.0.0.1', 'qwerty')


@app.before_request
def init_request_log():
if not hasattr(g, 'log'):
g.log = LogRecord(pg)

@app.route("/")
def hello():
g.log.set_field('hello_request',pack_request_log(request))
g.log.commit()
return "Hello World!"

if __name__ == "__main__":
app.run()

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

pglogs-0.1.5.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file pglogs-0.1.5.tar.gz.

File metadata

  • Download URL: pglogs-0.1.5.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pglogs-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0928e0c413d05b78200026823e125a9c742be196415b70878f3c4091f4ad0939
MD5 58ad6a9840c7af4c68c1e4d56d523993
BLAKE2b-256 2a40817b89dfcc1665ba6a51bccb42389dbd6bf68fc9d3beacff1fbf2f5b3640

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