dalibo / pgtoolkit

Postgres Support from Python
https://pgtoolkit.rtfd.io/
PostgreSQL License
21 stars 9 forks source link

Add message_type for PGAUDIT #115

Open qguang opened 1 year ago

qguang commented 1 year ago

PGAUDIT print message lines as below. 2023-07-24 01:53:45 UTC:[local]:postgres@crm_database:[68]: LOG: statement: revoke create on schema public from public; 2023-07-24 01:53:45 UTC:[local]:postgres@crm_database:[68]: LOG: AUDIT: SESSION,1,1,ROLE,REVOKE,,,revoke create on schema public from public;,<not logged> 2023-07-24 01:53:45 UTC:[local]:postgres@crm_database:[68]: LOG: statement: create schema crm_data authorization crm_adm_user; 2023-07-24 01:53:45 UTC:[local]:postgres@crm_database:[68]: LOG: AUDIT: SESSION,2,1,DDL,CREATE SCHEMA,,,create schema crm_data authorization crm_adm_user;,<not logged> 2023-07-24 01:53:45 UTC:[local]:postgres@crm_database:[68]: LOG: statement: alter schema public owner to crm_adm_user;

Is it possible to add more values to _types_prefixes? _types_prefixes = { "duration: ": "duration", "connection ": "connection", "disconnection": "connection", "automatic analyze": "analyze", "checkpoint ": "checkpoint", "AUDIT:": "pgaudit", }

dlax commented 1 year ago

Handling more message types would indeed make sense; but this should not be implemented by hard-coding another value, rather by adding a mechanism to extend the prefix-to-message_type map from user code. Something like:

import pgtoolkit.log

pgtoolkit.log.Record.register_message_type("AUDIT", "audit")
pgtoolkit.log.parse(...)

Or maybe as a parameter to parse()?