r/java • • 19d ago • Bravo 1

Rainbow Gum logging released v1.0.0 and why you should switch Now!

After 3 years and an embarrassing amount of personal and business time spent I finally am releasing Rainbow Gum 1.0.0.

I spent an enormous amount of time on Rainbow Gum because I know how important getting logging right is despite on the surface appearing very easy.

While I may be critical of the existing logging frameworks Rainbow Gum stands on the shoulders of these giants and why it is largely better is because of them.

Rainbow Gum is:

  • Is very secure. I can't say its more secure than the others because that would get me in trouble but if you were to put a gun to my head and ask me pick between Rainbow Gum, Logback, or Log4J2 not to have a security issue I would pick my library.
  • Faster than Log4J2 - Log4J2's claims of speed are very dated when zero GC options were vogue. Log4J2 is actually often slower than logback.
  • Smaller than Tinylog - Tinylog may have a small code footprint but it actually requires several dependencies like java.sql.
  • Loads of modern features - Scoped Values, colored themes, JSONL, LTSV built into core etc.

There really only 4-5 logging libraries (implementations) in the Java ecosystem so if your knee jerk reaction is not another one just know that there are way more JSON serializers, ORMs, web frameworks and build systems. All of these require tremendous effort to switch or even try.

With a couple changes of your POM you can switch to Rainbow Gum.

Please try it!

Rainbow Gum was coded by me entirely up to 0.10.0 I think. It is now heavily code assisted. I had to to make sure it was as secure as possible but have reviewed every change. I am exhausted! I have made it transparent by letting the agents coauthor the commits.

https://github.com/jstachio/rainbowgum

And if you don't think Rainbow Gum is as good as what I say it is you can always have several agents do a blind test on all the logging frameworks. Just tell them to remove authors and rename etc. You can and should always benchmark as well.

Special thanks to the JDK team and JSpecify team.

I will add more links later but if I add too many I will be automod.

44 Upvotes

34 comments sorted by

20

u/agentoutlier 18d ago edited 18d ago

Now I know there will be people rather upset that I used some AI tools (the mods informed me that any form of AI usage is not allowed but let this post) to help check and write Rainbow Gum. I have historically not used any of these tools. Rainbow Gum was not vibe coded but I used these tools to help setup testing and do testing as well as fill in the rest of boiler plate. I am approaching 50 and my fingers have a fair amount of arthritis. For proof you can see my other major project: https://github.com/jstachio/jstachio that I do not vibe code.

The decision to use those tools did not come lightly.

Understand that logging and lots of boring libraries like this are already pretty "soulless" and the creative aspects of API design as well the logo were done by me well before the tools became so powerful. I hand wrote the SVG.By the way that is why the documentation is rather ugly look wise precisely because I did not vibe up a theme.

Those are creative things.

What is not creative is implementing another facade or setting up benchmarks for the 100th time or a bot finding another CVE.

And unlike a lot of other projects including mainstream ones that have folks just checking code with only their name when clearly likely used assistance I have tried to make it is transparent as possible.

And Log4J2 is doing this as well. So is Spring Boot. I don't know how the mods are really going to enforce zero AI usage.

If someone really wants a hand crafted logging implementation I can try to fork where I started using them but realize it will not be as secure and I will have to reduce scope greatly.

6

u/chabala 17d ago

I am not offended by your use of AI tools. My interpretation of the intent of the rule is to curb the fly-by posting of new projects that are 90%+ AI generated.

9

u/yk313 18d ago

The anti-AI attitude of some folks around here is mind-boggling to me.
AI usage does not automatically mean vibe coding, and if someone still holds that belief - perhaps due to their bad experience with AI last year - then better start demystifying the whole thing by investing in agentic engineering: proper instructions, skills, hooks, etc.
With a proper setup, this year’s models write better code than most (if not all) people I have worked with. And writing code is just a small portion of what they are good at, there’s so much additional value in verification, conformance, observability, etc.
Don’t speed run into irrelevance/unemployment.

9

u/imagei 18d ago

For me, before I even look beyond the surface of another logging framework, I ask two questions: How is SLF4J compatibility? If 100%, then: is it a drop-in replacement for Logback ( beyond its private APIs and its config file, of course )?

How is Rainbow Gum faring on those two fronts?

12

u/agentoutlier 18d ago

Yes.

It speaks SLF4J like logback. If you go to: https://www.slf4j.org/ you can even see it in the drop down on the hamburger menu.

It is a drop in replacement for Logback for Spring Boot and/or if you don't use its logback.xml config. In fact if you just drop it in for Spring Boot using the starter it matches and reuses Springs color and the pattern layout so it can be confusing if it is even changed.

Obviously if you use Logback API or its XML you will have issues but I do have migrations guides.

3

u/imagei 18d ago

Thank you, that's good news. I don't fear config files, but I put a hard stop on even trying yet another logging library if that means touching one single line of application code 🤣

5

u/davidalayachew 18d ago

Ok, I have been keeping my eye on this, waiting for it to go live before seriously considering adding it to my actual production system.

So, several things I need to know.

  • Is this on any of the Spring Starter poms?
  • What is the rainbow gum equivalent to slf4j-simple?

    • For unit tests, basically.
  • What is the rainbow gun equivalent of logback-classic?

    • The single import I need to just log to console and/or file.
  • What is the splunk interop story like?
  • What is the AWS CloudWatch interop story like?

5

u/agentoutlier 18d ago

Is this on any of the Spring Starter poms?

Phillip merged in today in the starter list: https://github.com/spring-projects/spring-boot/pull/52807

What is the rainbow gum equivalent to slf4j-simple?

There are several options.

rainbowgum-simple : https://jstach.io/doc/rainbowgum/current/apidocs/#simple_bundle

logwood: https://github.com/jstachio/logwood (which is not released because it require rainbow gum 1.0 first) - Logwood has mostly compatible config with rainbow gum.

What is the rainbow gun equivalent of logback-classic?

Sadly I don't have a bundle for this but the closest is:

<dependency>
  <groupId>io.jstach.rainbowgum</groupId>
  <artifactId>rainbowgum[-simple]</artifactId>
  <version>1.0.1</version>
</dependency>
<dependency>
  <groupId>io.jstach.rainbowgum</groupId>
  <artifactId>rainbowgum-pattern</artifactId>
  <version>1.0.1</version>
</dependency>
<dependency>
  <groupId>io.jstach.rainbowgum</groupId>
  <artifactId>rainbowgum-file</artifactId>
  <version>1.0.1</version>
</dependency>

I put the [-simple] in the artifactId because it depends if you want to use logging.properties or not but the safe bet would be rainbowgum-simple.

The rainbowgum-pattern is if you plan to use pattern layout.

Don't worry if you miss anything the errors on output will tell you which module you are missing.

What is the splunk interop story like?

Use JSON (ECS or Logstash) to a file or stdout with the Universal Forwarder or Splunk's OTel Collector, or send OTLP to the Splunk OTel Collector. There's no direct HEC appender yet.

What is the AWS CloudWatch interop story like?

This one I can't answer. I'll have to lookup CloudWatch but I'm guessing its got some file based collector as well.

2

u/davidalayachew 18d ago

Phillip merged in today in the starter list: https://github.com/spring-projects/spring-boot/pull/52807

I didn't fully understand the PR link, but it sounds like it means that Rainbow Gum will be in Spring-Boot Starter Parent from 4.2.x onwards?

Sadly I don't have a bundle for this

Any chance you could? Ultimately, this is going to be the landing point for most people switching over -- the MVP that does what they are already doing.

Interop with things like Grafana and whatnot makes sense as separate modules. And the fact that you broke out the file-handling and the pattern-logic to separate modules is very admirable.

But it does help out immensely to have a single module that does the 90% use case of logging to console and file.

And this should be fairly cheap to create -- a Maven Module with the only source code being a module-info.java file, nothing else. It is just an aggregation of only the needed Rainbow Gum Modules to support this use case. We do the same all the time. And here is an example of something similar in the JDK itself -- the java.se module.

1

u/agentoutlier 18d ago

I didn't fully understand the PR link, but it sounds like it means that Rainbow Gum will be in Spring-Boot Starter Parent from 4.2.x onwards?

No its a third party list. It will be till I somehow get enough clout or stars or whatever to make it as an official maintained alternative like Log4J2 is. That is why I need people to try it. Star it. Like it. Tell your friends. Benchmark it etc.

And this you can help me on David. Logging is just straight up overhead. Every major application I have seen does logging and a typical request is often dozens of logging calls.

So just a few changes to most people who use stdout for logging can get immediate measurable performance boost. The benchmarks I did were not like JMH. They were straight up Spring Boot:

https://github.com/jstachio/rainbowgum/blob/main/why_rainbowgum_is_better.md#fast

The fact there is so much variance given how Spring MVC is not exactly super fast is proof how much impact logging does have an impact on application performance.

Any chance you could? Ultimately, this is going to be the landing point for most people switching over -- the MVP that does what they are already doing.

Yes I can. However realize a tool or even google once it indexes will tell you how to do it. The library itself even shows error messages to help:

Pattern module missing (-Dlogging.appender.console.encoder.uri=pattern):

SLF4J(E): Failed to instantiate SLF4J LoggerFactory
SLF4J(E): Reported exception:
io.jstach.rainbowgum.LogProvider$ProvisionException: Error for property. key: 'logging.appender.console.encoder.uri' from SYSTEM_PROPERTIES[logging.appender.console.encoder.uri], 
NotFoundException No encoder found. Scheme not registered. scheme: 'pattern', URI: 'pattern:///'. Scheme 'pattern' is provided by module 'io.jstach.rainbowgum.pattern' (Maven: 'io.jstach.rainbowgum:rainbowgum-pattern:1.0.1'). Add that dependency. See https://jstach.io/doc/rainbowgum/1.0.1/apidocs/index.html#pattern
  ↳ Failure providing Appender: 'console' from property: Fallback[logging.route.default.appenders]=[console].
  ↳ Failure providing Appenders for route: 'default'.

File module missing, Spring Boot style (-Dlogging.file.name=logs/app.log):

io.jstach.rainbowgum.LogProvider$ProvisionException: Error for property. key: 'logging.file.name' from SYSTEM_PROPERTIES[logging.file.name], NotFoundException 
No output found. Scheme not registered. scheme: 'file', URI: 'file:///app/logs/app.log'. Scheme 'file' is provided by module 'io.jstach.rainbowgum.file' (Maven: 'io.jstach.rainbowgum:rainbowgum-file:1.0.1'). Add that dependency. See https://jstach.io/doc/rainbowgum/1.0.1/apidocs/index.html#file
  ↳ Failure providing Appender: 'file' from property: Fallback[logging.route.default.appenders]=[file, console].
  ↳ Failure providing Appenders for route: 'default'.

I kind of messed up the pasting of the error but if you scroll to the right you can see how it gives a doc link and maven module.

3

u/davidalayachew 18d ago

And this you can help me on David.

Oh believe me, I am seriously considering your library here. If this adds up for me, we'll be switching from Logback to Rainbow Gum by mid-2027.

I'm not some passerby saying nice words to make you feel better about your project here.

Yes I can. However realize a tool or even google once it indexes will tell you how to do it.

I have 200+ Maven modules that I am genuinely considering to migrate from Logback to this by mid-2027. But that's also 200+ modules of maintenance, so I am considering the level of effort here too.

So, for me, I would much prefer having it all be a single import, so that I can simplify the management of it.

Any chance of this happening?

2

u/agentoutlier 18d ago

Possibly. You can file an issue on github so I don't forget!

Be specific on what current modules/config you are using of logback and specific logback config and I can get on it!

2

u/davidalayachew 18d ago

Possibly. You can file an issue on github so I don't forget!

Deal. I can make the PR too if you like. This is a small enough change that it should be quite easy to do.

Be specific on what current modules/config you are using of logback and specific logback config and I can get on it!

Sure, but it shouldn't require much adaptation on your part. It's mostly just the logback.xml config and then a few commandline flags.

But yes, I'll include that in the Issue and PR.

2

u/Jolly_Resolution_222 18d ago

I think / \ and .. should be rejected in the prefix and suffix otherwise could that lead to path traversal. rainbowgum-file/src/main/java/io/jstach/rainbowgum/rolling/RollingPolicy.java

3

u/agentoutlier 18d ago edited 18d ago

I did think of that but apparently the pattern was common enough that I decided to allow it. Permissions are checked and the file creations do the right thing as well. Also symlinks checked.

Rolling is the one area I really did not want to implement but reluctantly did and why throughout the doc I push heavily to use external tools: https://jstach.io/doc/rainbowgum/current/apidocs/#rolling

I highly recommend journald or k8s/docker log collection or logrotate which we do have excellent support for.

EDIT I suppose though given I don't want people to use rolling it is worth doing! Now I just can't decide what level of semver to use for that.

EDIT I should probably point out to other this is not a security threat because the user of the library has to set the file name pattern and you cannot change it once its set. Its more to prevent you from blowing away something you should not.

2

u/idontlikegudeg 14d ago edited 14d ago

EDIT: Fixed it. The correct pattern is:

"%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %X{userId} \\(%class.%method\\(%file:%line\\)\\) - %msg%n"

Plus it seems you need to manually configure that location information is needed using a ´LogPropertiesBuilder´.

---------

How would I configure the RainbowGm equivalent of this pattern?

"%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %X{userId} (%C.%M(%F:%L)) - %m%n"

I tried this and it does not work:

"%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %X{userId} (%class.%method\\(%file:%line\\)) - %msg%n"

I get no errors, but the rainbow gum output is like this:

2026-11-18 06:44:23.417 [org.slb4j.benchmark.RainbowGumBenchmark.jcl-jmh-worker-1] INFO  benchUser (.(:)

The expected format is this:

2026-11-18 06:17:53.981 [org.slb4j.benchmark.Log4jBenchmark.jcl-jmh-worker-1] INFO  benchUser (org.slb4j.benchmark.SampleOutput.lambda$writeIfConfigured$3(SampleOutput.java:80)) - Sample log output generated by LOG4J frontend

I used Rainbow Gum V 1.0.1 anf the appender is configured like:

appender.encoder(new PatternEncoderBuilder("benchmark").pattern(pattern).build());

1

u/agentoutlier 14d ago

If you can just file an issue.

Location information is generally expensive and I did not see many people use it so it’s good to see that someone needs it.

I will edit this comment later but yes  to turn on location is kind of odd in that I can only be properties.

2

u/idontlikegudeg 14d ago

Yes, will do that for the silent failure. After fixing the format, I get the expected result.

Just hope that you will do the same the next time.

2

u/agentoutlier 13d ago

I'm fixing it. It was a lapse on forgetting to add programmatic configuration for caller information before 1.0.

The silent failure is a bug. That will be fixed right away. I'm going to check to see if Logback has a similar bug.

Just hope that you will do the same the next time.

Yes I take full responsibility on neglecting location information aka caller info if that is what you mean.

We are also adding something like %ifCaller.

See the issue is that Logback is all or nothing on caller/location. If the pattern encoder has a caller/location configuration it will change how the event is created for all events.

Rainbow Gum allows you to choose which loggers you want this to happen on.

This is why it was not on the builder yet because turning it on is very much like setting a threshold for a logger so the properties way was done first.

In hindsight most don't need that flexibility and probably want it all or nothing like logback.

I think the doc did cover that it was only configurable for properties but no worries that will be fixed for 1.1.0.

1

u/idontlikegudeg 13d ago

OK, if you are already fixing it, I think theres no need to open an issue for this.

1

u/burl-21 18d ago

Currently, with spring-boot, we are using logback with opentelemetry-logback-appender-1.0 (logback.xml mdc attributes). Is there any guide available for migrating to rainbow gum? I'd like to try it out.

1

u/agentoutlier 18d ago

I'll take a guess how you use OTLP that you are not using the agent because the agent bypasses logging.

Rainbow Gum's rainbowgum-otlp exports OTLP itself, with no SDK and no protobuf library. Logs then have their own endpoint configuration, separate from traces and metrics. First do deps:

<dependency>
  <groupId>io.jstach.rainbowgum</groupId>
  <artifactId>rainbowgum-spring-boot4-starter</artifactId>
  <version>1.0.1</version>
</dependency>
<dependency>
  <groupId>io.jstach.rainbowgum</groupId>
  <artifactId>rainbowgum-otlp</artifactId>
  <version>1.0.1</version>
</dependency>
<!-- adds traceId/spanId from the current span, like the appender does -->
<dependency>
  <groupId>io.jstach.rainbowgum</groupId>
  <artifactId>rainbowgum-opentelemetry</artifactId>
  <version>1.0.1</version>
</dependency>

Exclude spring-boot-starter-logging like:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <!--
      This is the important part as logback will be used otherwise
      regardless if rainbow gum spring boot integration is used.
    -->
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Configuration goes in application.properties or YAML, because the starter reads it from Spring:

logging.appenders=console,otel
logging.appender.otel.output.uri=otlp:///
logging.appender.otel.output.otlp.endpoint=http://collector:4318/v1/logs
logging.appender.otel.output.otlp.serviceName=orders
# the equivalent of captureMdcAttributes
logging.appender.otel.output.otlp.keyValuesIncluded=requestId,user.id
logging.route.default.publisher.uri=async

I took the above from various tests of ours but if you are not against certain tools they can easily do it for you as our doc has guides for these tools.

1

u/Drawhoe 16d ago

I use logback classic. How would I try your logger out?

2

u/agentoutlier 16d ago

The easiest way is to use a tool that will read the logback migrating guide. I have even tested this on local small tools and it usually works.

The more manual way is to simply remove the logback classic dependency and add io.jstach.rainbowgum:rainbowgum-simple:1.0.1 as a dependency.

Then you will make a logging.properties instead of a logback.xml file.

If you are using Spring Boot you would use the special integration modules for that: io.jstach.rainbowgum:rainbowgum-spring-boot4-starter.

If you paste your logback.xml here or a version of it I can convert it for you.

1

u/Drawhoe 15d ago edited 15d ago

ok thanks!

2

u/agentoutlier 15d ago

So roughly:

# Rainbow Gum version of logback.xml.
# Needs rainbowgum, rainbowgum-file, rainbowgum-pattern and rainbowgum-simple-props.

logging.appenders=A1,R

logging.appender.A1.output.uri=stdout
logging.appender.A1.encoder.uri=pattern
logging.appender.A1.encoder.pattern.pattern=%d{HH:mm:ss} [%c{0}] %m%n

# No ${user.home}: logging.properties values are not interpolated, so use the real path.
# Rolling is size based only (no daily %d rollover). Archives are goldchest.log.1 to .4.
logging.appender.R.output.uri=rolling:///home/YOU/goldchest/goldchest.log
logging.appender.R.output.rolling.maxFileSize=10MB
logging.appender.R.output.rolling.maxHistory=4
logging.appender.R.encoder.uri=pattern
logging.appender.R.encoder.pattern.pattern=%-5p %d{MMM dd HH:mm:ss} %c - %m%n

logging.level=WARN
logging.level.org=ERROR
logging.level.net=ERROR
logging.level.game=WARN
logging.level.game.core.Roller=WARN
logging.level.game.combat.NodeFactory=ERROR

A couple of things you need to beware of is that Rainbow Gum simple properties (rainbowgum-simple-props) does not interpolation.

So this:

logging.appender.R.output.uri=rolling:///home/YOU/goldchest/goldchest.log

Will require you do something about since you can't use ${user.home} and I put YOU in place.

This largely depends on how you deploy your app but one option is to just write to the current working directory instead of relying on home.

Another option is to use programmatic configuration.

/**
 * Rainbow Gum version of logback.xml. Found with the ServiceLoader, see
 * META-INF/services/io.jstach.rainbowgum.spi.RainbowGumServiceProvider.
 */
public final class GoldchestLogging implements RainbowGumProvider {

  @Override
  public Optional<RainbowGum> provide(LogConfig config) {
    Path logFile = Path.of(System.getProperty("user.home"), "goldchest", "goldchest.log");
    return RainbowGum.builder(config) //
      .route(r -> {
        r.level(Level.WARNING);
        r.level(Level.ERROR, "org");
        r.level(Level.ERROR, "net");
        r.level(Level.WARNING, "game");
        r.level(Level.WARNING, "game.core.Roller");
        r.level(Level.ERROR, "game.combat.NodeFactory");
        r.appender("A1", a -> {
          a.output(LogOutput.ofStandardOut());
          a.encoder(new PatternEncoderBuilder("A1") //
            .pattern("%d{HH:mm:ss} [%c{0}] %m%n")
            .build());
        });
        r.appender("R", a -> {
          // Size based rolling: goldchest.log.1 to .4 next to the active file.
          a.output(new RollingFileOutputBuilder("R") //
            .fileName(logFile.toString())
            .maxFileSize(DataSize.ofMegabytes(10))
            .maxHistory(4)
            .build());
          a.encoder(new PatternEncoderBuilder("R") //
            .pattern("%-5p %d{MMM dd HH:mm:ss} %c - %m%n")
            .build());
        });
      }) //
      .optional();
  }

}

1

u/Drawhoe 15d ago

I see. Very cool! Thanks, I'll try it out.

1

u/ducki666 18d ago

Why should I use it instead of logback?

8

u/agentoutlier 18d ago

This is roughly covered in: https://github.com/jstachio/rainbowgum/blob/main/why_rainbowgum_is_better.md

I suppose if were to name a big one is that getting GraalVM native to work with logback and log4j2 is harder.

Rainbow Gum allows you to use newer things like Scoped Key Values in place of MDC.

Rainbow Gum is more likely to embrace newer JDK features.

The Javadoc and doc in general is IMO superior.

Rainbow Gum has a metrics system for observability.

Rainbow Gum the project maintains most of the plugins where as logback has lots of third parties managing them. I found rather large memory bugs in the the third party logstash module and would have filed bugs but its unclear if it is still maintained.

Logbacks custom default JSON encoding is questionable. There is a bug open that still does not escape correctly. (Rainbow Gum btw does offer Logback JSON format if you prefer it).

7

u/CptGia 18d ago

More secure than others... Based on what? Vibes? 

2

u/Kango_V 18d ago

I am using Rainbowgum in my current project and it's working very well. I've used JStachio (same author) in a few previous projects along with Micronaut, PicoCLI and GraalVM. JStachio is great as you don't need it at runtime.

1

u/MinimallyLoquacious 17d ago

> I can't say its more secure than the others because that would get me in trouble but if you were to put a gun to my head and ask me pick between Rainbow Gum, Logback, or Log4J2 not to have a security issue I would pick my library.

Sounds more like feelings than logic.

I'll stick with Logback since I do not see enough justification to cause new churn in my projects, not when logging can be so critical.

2

u/agentoutlier 17d ago

Its based on my experience with working on Logback.

This fix has been opened since 2024 and is still not in any release builds:

https://github.com/qos-ch/logback/issues/866

There are many more issues like this. I have contributed to logback in the past and worked with Ceki on things so I don't like criticizing it.

I cover a lot of the problem with the libraries here:

https://github.com/jstachio/rainbowgum/blob/main/why_rainbowgum_is_better.md

I'll stick with Logback since I do not see enough justification to cause new churn in my projects, not when logging can be so critical.

Indeed it is and why I wrote Rainbow Gum. However you are happy with Logback and don't need perf boost, graalvm native, scoped values etc then staying with logback is a sensible choice.