Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you properly format json messages and send them over amqp with syslog-ng?

The json format should look something like this.

{"log":"This is the error message...", "date":"xxx", "source":"xxx"}

The problem I have is that the message is not always a valid json string.


"log":"This is a "serious" error message."

How would I go about escaping the message?

My syslog-ng configuration looks something like this.

destination d_amqp {
        username("guest") # required option, no default
        password("guest") # required option, no default
            scope("selected-macros" "nv-pairs" "sdata")

This is just an example, as I don't have the actual configuration in front of me right now.

share|improve this question
up vote 3 down vote accepted

You should use the $(format-json) template function instead of handcrafting the json payload.

That will do the escaping for you. Not to mention that you can query the set of name-value pairs within a message and make the json more dynamic, for instance by adding all name-value pairs with a specific prefix.

Here is a link to the documentation:

Algernon has posted a lengthy blog post on json too. See here:

share|improve this answer
would you care an show an example? – DerStoffel Jun 26 '15 at 11:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.