question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

end prefix with a space

See original GitHub issue

Hey guys,

whenever I add a space at the end of my pattern it’s not respected. I tried to use xml:space="preserve" but it doesn’t work.

I’d like to get something like

<14> 2016-10-07T21:10:42.458Z log.json {"@timestamp":"2016-10-07T23:10:42.458+02:00"...

but I get

<14> 2016-10-07T21:10:42.458Z log.json{"@timestamp":"2016-10-07T23:10:42.458+02:00"...
                                      ^

Here is the configuration I use :

<appender name="loghost" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
    <remoteHost>localhost</remoteHost>
    <encoder class="net.logstash.logback.encoder.LogstashEncoder">
      <prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
          <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern xml:space="preserve">&lt;14&gt; %date{"yyyy-MM-dd'T'HH:mm:ss.SSS", UTC}Z log.json </pattern>
          </layout>
      </prefix>
   </encoder>
  </appender>

Any idea how to fix it ?

Thank you

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
philsttrcommented, Oct 9, 2016

Ah hah! I just found another hack/workaround that doesn’t require any code.

Try this:

<pattern xml:space="preserve">&lt;14&gt; %date{"yyyy-MM-dd'T'HH:mm:ss.SSS", UTC}Z%1mdc{keyThatWillNeverExist}</pattern>

This tells logback to output the MDC value with the key named keyThatWillNeverExist (which obviously doesn’t exist), and pad the value by 1. This will always output one space.

0reactions
cscetboncommented, Oct 10, 2016

Thank you so much @philsttr. It works exactly like I wanted. I was going to use your first method when I saw it but not having to compile anything is far better. I agree that we should have a way to add a space without using such hacky ways … FYI, I’ve also removed xml:space="preserve" which doesn’t seem necessary

Read more comments on GitHub >

github_iconTop Results From Across the Web

logfellow/logstash-logback-encoder - end prefix with a space
Hey guys, whenever I add a space at the end of my pattern it's not respected. I tried to use xml:space="preserve" but it...
Read more >
PREFIX WITH "SPACE" crossword clue
All solutions for "Prefix with "space"" 17 letters crossword clue - We ... 'PREFIX WITH "SPACE"' is a 17 letter Phrase starting with...
Read more >
How to Prefix Substrings in a Space-Delimited String in Shell ...
So we're all on the same page, by "portable" I mean "portable across different linux shells (sh, bash, ksh, zsh, tsh, csh, etc.)"...
Read more >
bot's prefix with space on end - Forums - Discord Bot Maker
I dont think you can have a space in the prefix or the command. You can specify seperate parameters after that but the...
Read more >
Prefix For 'Space' - Crossword Clue Answers
93%, HYPER, Prefix for 'space' ; 3%, NEO, Prefix for 'pronoun' ; 3%, VACUUM, Empty space ; 3%, SLOT, Schedule space.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found