Passing a JsonTemplateLayout'ed Log message to a Clickhouse #2448
Replies: 5 comments
-
|
Beta Was this translation helpful? Give feedback.
-
I suspect you have multiple
Make the
I am not able to follow you. Can you explain in detail what do you want to write to your ClickHouse database/table?
Good question. Writing an efficient and resilient appender is not trivial. You can check out |
Beta Was this translation helpful? Give feedback.
-
He is getting a layout from .jar file itself, so I guess I should just ignore this WARN cause there is nothing to do with it.
That's done, thanks for a hint. I am getting a JSONFormatted message within LogEvent like this: @Override
public void append(LogEvent event) {
String serializedEvent = (String) getLayout().toSerializable(event);
System.out.print(serializedEvent);
}
My ClickHouse DB contains a table with one field - (log JSON), so there is a format named JSON. I want just to pass my JSON'ed string to a db so I could store all my logs there with JSON format of the field.
Yeah, seems like it's working like that, mentioned here - ClickHouse-Java Issues/Passing JSON to a DB. I'm going to try that. |
Beta Was this translation helpful? Give feedback.
-
{
"exception": {
"stackTrace": ""
},
"mdc_fields": {
"compression_rate": "4.671450264565971",
"data_size": "40.24454402923584"
},
"message": "Compression of 40.24 MB of data with rate 4.67 MB/sec finished in 8.62 sec.",
"severity": "INFO",
"thread": "pool-2-thread-4",
"timestamp": ""
}
But it results in having \r\n, however I need UNIX style sequences for inserting my string. One of the solutions is like this -
|
Beta Was this translation helpful? Give feedback.
-
So, a total answer for anyone who might find this discussion useful:
Rename a layout file and passing it to a .xml configuration or somewhere else totally fix the WARN issue.
ClickHouse sorting all data automatically, that why it's seems to be reversed, it's just sorted.
That appears to be because clickhouse stores a row structure under JSON format for a first input record, so if other records doesn't contain any info for a field, then it just puts "" there. That's why timestamp is "" - it was removed from client-side template, but still remained in the server table structure.
I don't know still about making a pattern for a resolver, however about delimeters - two ways:
The issue on the clickhouse site, somehow it's just can't accept escape sequences in the message, so all \r\n\t was replaced with some other delimeter, for example, or could be just removed. |
Beta Was this translation helpful? Give feedback.
-
My main goal is to log all my messages with
LOGGER.info(...)
or something like this in JSON format. I've reached that by using this in my .xml configuration :<JsonTemplateLayout eventTemplateUri="classpath:GcpLayout.json"/>
.I got 3 questions:
2024-04-05T16:08:34.125664500Z main WARN for URI classpath:GcpLayout.json found 2 resources, using the first one: ...
, however, in my resource folder I have only oneGcpLayout.json
file. So where is the second one? I guess it's some default generated implementation template, but I couldn't find this template in files, so I could disable this WARN message.So, I want to pass a whole JSON Log message
As it is to my clickhouse Database, so I just need to recover this message as String, possibly.
I've seen about this discussion - #2013, but I find putting all my parameters in MDC might be a little bit strange to do, so I'm asking about other possibilites.
Beta Was this translation helpful? Give feedback.
All reactions