5 ms·
> just a wrapper around printf which adds a timestamp and a log-level That's a pretty naive view of what's needed in an enterprise logging solution. logging t
by nostoc 5y ago
> just a wrapper around printf which adds a timestamp and a log-level
That's a pretty naive view of what's needed in an enterprise logging solution.
logging to files, separate logging, remote logging, log rotation, logging 3rd party code...
Of course if you're simply sending lines to the terminal in a simple program you don't need log4j.
But once you scale, you'd be spending 3 weeks implementing what you get for free in log4j.
- oasisbob 5y agoLog4j configuration isn't free either. Ask anyone who has ever been woken up by an asinine log rotation bug. (The tailer broke, or the rotation didn't happen... again, etc) Playing application log janitor is miserable. Just ship the logs and be done with it.
- rtpg 5y agoI mean if you write log rotation code yourself you will still be woken up by it. I agree that log configuration is a pain in the butt and oftentimes messy (especially when some third party lib includes a line to basically wipe your global config and everything gets wonky), but it's not like the heavy value adds are easy and bug-free to write!
- nostoc 5y agoI'll agree to this, but it's still a lot better than trying to implement it yourself.
- oasisbob 5y agoI agree, writing (and arguably configuring) robust logging libraries isn't much fun, and not easy to do yourself. So, don't. Ship the logs as quickly and as simply to a system which is explicitly for log management. The choice isn't between writing huge logging libraries or using log4j, it's whether you want an application to handle its own flat-file logging and rotation in the first place. Java has always been obnoxiously complex to steer towards sane, basic, modern syslog, which I think is a shame.
- vbezhenar 5y agoIMO enterprise logging solution should write logs to file and rotate files. The rest should be done by a separate services like Loki or Logstash.
- dijit 5y agoArguably log rotation should be handled outside of the application with logrotate or filebeat.
- coredog64 5y agoPlease not filebeat. For a few months I had this recurring problem where an app was logging way too much stuff. Filebeat dutifully accepted it and then created ghost files as a buffer which then filled up the disk and crashed the app. Depending on the velocity at which the log barf was being produced, we sometimes had a short window in which we could manually (!) log in via SSH (!) and restart filebeat to force it to close the open file handles at the cost of losing everything being buffered locally (!).
- tetha 5y agoImo, the main point of a system like log4j or slf4j if the ability to have logging in your service up to the point of it being a massive performance impact - and keep it disabled. For example, Hibernate has full query logging built in, but even if you filter locally with some logging demon, pushing 100 - 1k queries / second to stdout or a file is going to cripple performance. With a logging framework like Log4J or SLF4J you can have this query logging, and you can enable it within 1 monitor run (usually 60s) at runtine and disable it 4-5 minutes later. This is very, very powerful in production.
- cozzyd 5y agoI thought you just rely on rsyslog or journald for this stuff...
- ninkendo 5y agoRight? Logs are streams, not files. To a first approximation, you should just log to standard out, and let another system take care of sending your output to either a file (with rotation) or logstash, or syslog, or a whatever else is appropriate. To a second approximation (if you’re already using stdout for something else), the thing you’re logging to should still be a file descriptor, but not a file per se. (perhaps a local socket to a logging system like syslog.) I don’t need everything on my system that logs, to invent its own log output directory, and implement its own log rotation. That’s how you get a mishmash of different places where logs end up living, and they become very difficult to collate or compare, etc.
- christophilus 5y agoYou do. None of the logging libraries I’ve used in the past 5 years even have log rotation as a feature, from what I can tell.
- Nursie 5y ago> Of course if you're simply sending lines to the terminal in a simple program you don't need log4j That's the issue though isn't it, a lot of people don't need those features, just the prettifying and formatting, levels selectable by classpath and basic bits. log4j is great at these things and has become the standard for these things as much as anything else. And with a lot of stuff being done by microservices, serverless functions etc, you have other pieces that pick up the logs and do all the smart processing. Especially 'at scale'. So a capable but simple logging library is probably a good option. Perhaps log4j could split.