Custom field in IDBC writer?

28 Views Asked by At

I have a application where I am using logging for the app, but I also want to do an audit log to the sql server. I was going to use tagging to specify what I want to log to the sql server, but how do I add a custom column / field to specify the user of said log entry? I have columns for timestamp, tag, level and message but I also have a column for user. what do I put into the "writer.field.user = ???" to specify what I want that column to have? This would be the same value for each instance and duration of the app when they log in. I have TinyLog v2.6.2. Thanks!

1

There are 1 best solutions below

1
Martin On BEST ANSWER

For your use case, I suggest to use context values for your custom fields. For example, when the user logs in, you can store the user name via ThreadContext.put("user", name).

Afterwards, all log entries, which are issued by the same thread or of one of its child thread, will be enriched by the stored context values. You can use the placeholder {context: key} for assigning context value to SQL table fields. If you have stored the user name with the key user in the thread context, you can assign it via writer.field.user = {context: user}".

If you use a thread pool or if you reuse threads for different users, you have to take care of clearing the thread context before reusing a thread.