No project description provided
Project description
log_to_db
Be able to log to a database.
Features
- Can log to the following databases:
- PostgreSQL
- SQLite
- DuckDB
Quickstart
Install
> pip install log_to_db
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 log_location.logs;
drop table if exists log_location.log_levels;
create table log_location.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 log_location.log_levels (
level int not null
,name text not null
);
-- Insert log_level data
insert into log_location.log_levels (level, name) values
(10, 'debug')
,(20, 'info')
,(30, 'warning')
,(40, 'error')
,(50, 'critical');
This is using PostgreSQL as the example database with log_location 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 log_to_db.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@yourhost: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 or DuckDB instead, replace connection_info to the file location
of the SQLite database file.
For either of these databases, it will be either SQLiteLog from sqlite_log
or DuckDBLog from duckdb_log.
Note file-based databases currently have a custom schema.
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.2.0.tar.gz.
File metadata
- Download URL: log_to_db-0.2.0.tar.gz
- Upload date:
- Size: 60.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3af4083834d0e37534f44776d65fec634664a1f2e1d743650b7b9ac6cdac123f
|
|
| MD5 |
81cc4bafec33f21c94c41b31e30bd30f
|
|
| BLAKE2b-256 |
9faf1e11e0251254a0a4dd87dea232580ca112d959318720c62af7d424196f63
|
File details
Details for the file log_to_db-0.2.0-py3-none-any.whl.
File metadata
- Download URL: log_to_db-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75e5b727c99bfe85e045ff99d30f2f63b93730a75582f2bc8f7824bf915f60d4
|
|
| MD5 |
3fabab0f1abb30fc8ab92d5e82a94757
|
|
| BLAKE2b-256 |
7d88dea30cd9ab04a4d3430217fb19b9f984a9c652ad1aa38082140d5e7c7ec2
|