audit4j / audit4j-core

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

Is there any way to save audit event fields as json in database? #51

Closed yangziwen closed 6 years ago

yangziwen commented 7 years ago

Dear author

I'm trying to find a way to save the content of elements column in json format, because I only care about values and don't want to save too many infos about objects' types.

It seems hard to override method behaviors of some important classes(such as DefaultAnnotationTransformer). Do you have any suggestion?

janithb commented 7 years ago

Hi @yangziwen
You can use use Layouts for the json layout. It is not such hard to write your own filter or use CustomizableLayout . You can even filter unwanted information using a custom layout.

yangziwen commented 7 years ago

Thanks so much for your reply.

Currently I import a customized ObjectSerializer via audit4j's commands configuration, and use it working together with CustomizableLayout to output json format audit fields to console or file.

But I still can not persist these fields to database as complete json format, because AuditLogDaoImpl#writeEvent method simply concat all fields with ',' as separator, then I can not eliminate the last ',' and add the outmost curly braces before insert the content to database.

Should I implement DatabaseAuditHandler and AuditLogDaoImpl by myself, or is there any other elegant way to solve the problem?

janithb commented 7 years ago

You are absolutely correct. That is a limitation of DB handler and you need to use a custom DB handler to insert the text as string. In the meantime I'll find a solution to fix this issue.

I would really appreciate if you can share your JSON serializer implementation. We do accept pul requests.

janithb commented 6 years ago

This is fixed

belchandan commented 6 years ago

I am also looking for similar, Values for Fields are not very readable for complex objects (e.g. beans or collection etc), is there ways to customize that?

Thanks

belchandan commented 6 years ago

Got it, just for confirmation and may be useful for someone like me: We can set AnnotationTransformer to use specific ObjectSerializer, like ObjectToJsonSerializer in this instance.

yangziwen commented 6 years ago

Since the annotationTransformer property in SpringAudit4jConfig is still not available in the latest release (2.4.1) of audit4j-spring, do you have any plan to give the next release in the near future? @janithb

janithb commented 6 years ago

audit4j 2.5.0 is already release. this issue is already fixed in 2.5.0 version.

leandrosilvaferreira commented 6 years ago

Hi guys ( @janithb @yangziwen ), there are a documentation somewhere about save the content of elements column in json format? Thanks!

koti-muppavarapu commented 1 year ago

Hi,

Could someone provide me an example configuration to log elements field on audit table store json string of an object?

koti-muppavarapu commented 1 year ago

Never mind, I have figured it out. It's as simple as this...

audit4jConfig.setAnnotationTransformer(new DefaultAnnotationTransformer(new ObjectToJsonSerializer()));