Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tinylog via SLF4J cannot handle text within curly brackets #132

Closed
sanderdg opened this issue Jan 13, 2020 · 10 comments
Closed

Tinylog via SLF4J cannot handle text within curly brackets #132

sanderdg opened this issue Jan 13, 2020 · 10 comments
Milestone

Comments

@sanderdg
Copy link

I'm currently trying to use a project that adds curly brackets to log statements like this;logger.info("{foo} {}", "bar"). Tinylog tries to process {foo} as a placeholder that needs to be replaced by something but that isn't the case obviously. Only {} should be replaced by bar.

Expected result: {foo} bar

Actual output: LOGGER WARN: Illegal argument 'bar' for pattern 'foo' (which is created by MessageFormatter in format(final String pattern, final Object argument) on line 116)

@pmwmedia
Copy link
Member

pmwmedia commented Jan 13, 2020

tinylog expects a DecimalFormat or ChoiceFormat compatible pattern in the curly brackets. But 'bar' isn't a compatible pattern either of them. For example, Logger.debug("Income: {0.00} EUR", 42) is a valid log statement and would output Income: 42.00 EUR.

For solving your issue, a way for escaping curly brackets is required. I'm thinking about something like logger.info("\\{foo\\} {}", "bar").

@pmwmedia
Copy link
Member

By the way, Logger.info("{foo} bar") works as tinylog doesn't parse curly brackets, if there are no arguments.

@pmwmedia pmwmedia added this to the 2.2 milestone Jan 13, 2020
@sanderdg
Copy link
Author

Thanks for checking this out. The project that causes this problem isn't mine so I cannot escape all curly brackets. If I can find some time I'll look into this.

@pmwmedia
Copy link
Member

What is the class name of the logger in the statement logger.info("{foo} {}", "bar")? Is it a tinylog logger or a third-party logger?

@sanderdg
Copy link
Author

sanderdg commented Jan 15, 2020

It's a third-party logger that implements org.slf4j.Logger. Tinylog takes it from there of course. The project which I'm having the issue with is Atomix. The issue can be reproduced with the following steps:

  • Perform git clone https://github.com/atomix/atomix
  • Go to the tests module and replace the logback dependency with:
    <dependency>
      <groupId>org.tinylog</groupId>
      <artifactId>tinylog-impl</artifactId>
      <version>2.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.tinylog</groupId>
      <artifactId>slf4j-tinylog</artifactId>
      <version>2.0.1</version>
    </dependency>
  • Run the RaftPerformanceTest

Furthermore logger.info("{foo} {}", "bar") does seem to work when using it directly from Tinylog so I've modified the title of the issue a bit to make it more precise.

@sanderdg sanderdg changed the title Tinylog cannot handle text within curly brackets Tinylog via SLF4J cannot handle text within curly brackets Jan 15, 2020
@pmwmedia
Copy link
Member

@sanderdg Thank you for the clarification.

I think we need two different solutions:

  1. For the third-party logging API like SLF4J, replace only{} and treat all others like {foo} as plain text.
  2. For tinylog API, the ability to escape curly brackets, as suggested earlier.

@pmwmedia
Copy link
Member

I have implemented it on the v2.1 branch. All third-party logging API like SLF4J should keep {foo} untouched now and replace only curly brackets without any text between.

@sanderdg Could verify if it works for you, too?

slf4j-tinylog-2.1-SNAPSHOT.zip
tinylog-2.1-SNAPSHOT.zip

Additionally, it is possible to escape phrases by ticks now, if using tinylog's native logging API. For example: '{foo}'.

@sanderdg
Copy link
Author

I've verified it and it works. Thanks for fixing this! 👍

@pmwmedia
Copy link
Member

Thank you for verifying :-) I will release it as RC2 soon.

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

This closed issue has been locked automatically. However, please feel free to file a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants