No project description provided
Project description
db_logging
Be able to log to a database.
Features
- Can log to the following databases:
- PostgreSQL
- SQLite
- DuckDB
Quickstart
Install
> pip install db_logging
Setup
The database will need to be created ahead of time. The table structure will need to be:
create schema if not exists programs;
drop table if exists programs.logs;
drop table if exists programs.log_levels;
create table programs.logs (
entry timestamptz not null default now()
,program text not null
,pc_name text not null
,level int not null
,message text not null
,details jsonb null
);
create table programs.log_levels (
level int not null
,name text not null
);
-- Insert log_level data
insert into programs.log_levels (level, name) values
(10, 'debug')
,(20, 'info')
,(30, 'warning')
,(40, 'error')
,(50, 'critical');
This is using PostgreSQL as the example database with programs as the schema.
However, the log table name will need to be logs.
Note log_level table is not required but this makes it easier to build queries.
SQLite would be similar but the schema won't be included.
Example Usage
To use in a program for example:
from db_logging.postgres_log import PostgresLog
db_logger = PostgresLog(
save_level="debug",
pc_name="test_pc",
program_name="test_program",
program_timezone="America/Chicago",
connection_info="postgres://user:password@youhost:5432/log_database",
schema="log_location",
)
db_logger.info(
message="Starting program.",
details=dict(
test_data="This is a test.",
)
)
db_code = db_logger.save_log()
To use SQLite instead, replace connection_info to the file location of the SQLite database file.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file log_to_db-0.1.0.tar.gz.
File metadata
- Download URL: log_to_db-0.1.0.tar.gz
- Upload date:
- Size: 56.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d550d662b9bc7494334ef4502b08b2f60cca4534591881c7f13973a3338d042
|
|
| MD5 |
87beaac1f6b84b85cd386472163d0b53
|
|
| BLAKE2b-256 |
e58fbaa2daf2fc4df7773d9815af69d07763aeab4b6e7978e609376c59e412d0
|
File details
Details for the file log_to_db-0.1.0-py3-none-any.whl.
File metadata
- Download URL: log_to_db-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15e72ae3b17efb088ec73cc54a07d6c065772ca5b3a30546c7d7788354dcc131
|
|
| MD5 |
fe21163792924cb8df1c8b02b9917bea
|
|
| BLAKE2b-256 |
9384cad504d707c69ea649e2ffdf285c0480c2fab5e91bf5cb3e5ad0f262ea7a
|