audit4j / audit4j-core

An open source auditing framework.
http://audit4j.org
Apache License 2.0
125 stars 77 forks source link

Timestamp format for database auditing #77

Open johno1985 opened 6 years ago

johno1985 commented 6 years ago

I am trying to store the audit timestamp with the UTC timezone included in the database. I am using the following config

!Configuration
handlers:
- !org.audit4j.handler.db.DatabaseAuditHandler
    embedded: false
    db_driver: com.mysql.cj.jdbc.Driver
    db_url: jdbc:mysql://localhost:3306/launchbi_audit_local?serverTimezone=UTC
    db_user: ***
    db_password: ***
layout: 
  !org.audit4j.core.layout.SimpleLayout
    dateFormat: MM/dd/yyyy HH:mm:ss zzz

But this has no effect, the timestamp is stored without the timezone

I am using audit4j-core version 2.5.0 and audit4j-db version 2.5.0

franck-benault commented 6 years ago

Hello,

following to documentation http://audit4j.org/documentation/#layouts the layout allows you to format the audit traces in console or file, not in database

I understand to need and you can a similar problem here https://github.com/audit4j/audit4j-db/issues/9

in fact for the audit in database there is not format possible if you look at the code of AuditLogDaoImpl in Audit4j-db everything is hard coded (timestamp and element).

please take also in account that this date event is store in a TIMESTAMP column not a VARCHAR column

in the code of audit-db, you have statement.setTimestamp(2, new Timestamp(event.getTimestamp().getTime()));

we shoud use the version with three parameters to force the time zone example with time zone UTC statement.setTimestamp(2, new Timestamp(event.getTimestamp().getTime()), Calendar.getInstance(TimeZone.getTimeZone("UTC"))));

please, look at your problem again and send a feed back with your need.

Regards Franck