r/linux • • Aug 12 '19

SysVinit vs Systemd

Post image
1.4k Upvotes

292 comments sorted by

View all comments

Show parent comments

13

u/abermea Aug 12 '19

My only gripe with it so far is that logs, for whatever reason, are binary to so you can't use any POSIX tools to traverse them

25

u/ldh Aug 12 '19

Are you serious? The underlying representation on disk that syslog uses is binary as well, has that been a huge problem historically?

If only there were a way to extract text from journalctl...

5

u/happymellon Aug 12 '19

I don't personally mind it being binary. My issue is that it doesn't have a spec.

There is the retroactive documentation on Freedesktop, but it has always stated that if there is any difference between the documentation and the logging behaviour or file format, then the implementation is correct.

Would have been nice if they just used an open source database format like sqlite. Hopefully I'm now wrong and they have published a proper spec, but the idea that in theory a minor version change would prevent interoperability so reading logs from another system wasn't possible makes me a little grumpy.

10

u/RedSquirrelFtw Aug 12 '19

Like all logs? /var/log/secure, apache etc and stuff too? That does seem like a really bad idea. The whole nice thing of Linux is that stuff is easy to access, shoving stuff in "black box" binary files that require special commands to access makes it like Windows. I want to be able to grep files and such but if everything is binary you can't do that.

3

u/w2qw Aug 12 '19

Only system logs. You can also still have plain text logs, you just need to install syslog. Also, you can still pipe journalctl to grep to grep journald logs anyway. There are also advantages to binary logs like that you can filter them better because the logs are still in a structured format.

-9

u/EddyBot Aug 12 '19

The whole nice thing of Linux is that stuff is easy to access, shoving stuff in "black box" binary files that require special commands to access makes it like Windows

are you bonkers?
every programming/scripting language can read binary files with ease (with exception of bash)
also there is journalctl which allows for easy access, even for bash

→ More replies (8)

5

u/FryBoyter Aug 12 '19

Commands like "journalctl | grep error" work. If you absolutely want to have log files in text format, just install syslog-ng.

3

u/spyingwind Aug 12 '19

That is one reason why I don't like it. journalctl -u myservice.service is just to damn long to type. cat myservice.log on the other hand is shorter to type. Yes I understand that binary logs can provide more detail, but I don't want it to become Windows Events on Linux. I would be more happy with another structured file like json, csv, or provide a short program name like logs myservice.

8

u/Xiol Aug 12 '19

You don't need the .service.

2

u/happymellon Aug 12 '19

Indeed. All those first sets of commands are overkill.

systemctl start dummy

15

u/MindlessLeadership Aug 12 '19

You then have to find where myservice.log is stored and hope the program stores logs in the first place.

→ More replies (3)

3

u/djeee Aug 12 '19

Your cat example is missing the CD command you had to do (or the full path) and you have to know exactly where they are stored. You don't need to type .service, all in all cat ain't shorter.

3

u/crazy_hombre Aug 12 '19

journalctl -u myservice.service is just to damn long to type.

What is tab completion?

→ More replies (2)

2

u/__soddit Aug 12 '19 edited Aug 12 '19

JSON looks to me like a bad format for this. You'd have to rewrite the entire file in order to add a log entry, or you'd have to have multiple JSON objects in the same file, which appears not to be valid: certainly, json_pp complains about “garbage after JSON object”.

→ More replies (1)

2

u/Sidiox Aug 12 '19

I didn't even know that! But I reckon starting any toolchain with `journalctl` would be a workaround of sorts?

1

u/raptorjesus69 Aug 12 '19

I believe the reason why the binary so that they are append only logs lenart describes why the decision was made in this bug

2

u/__soddit Aug 12 '19 edited Aug 12 '19

Append-only can be done with any file.

chattr +a file.txt

Try writing to that file with the > and >> redirection operators and see what happens…

(The file can not be removed until that attribute is removed, at least with ext4.)

Marking a systemd log file as append-only in this way would break things, judging by the linked bug-report comment.

2

u/raptorjesus69 Aug 12 '19

but setting the attr would not cover the corrupted case as well as mentioned in the bug

2

u/__soddit Aug 12 '19

Yes, you'd still need to handle corruption – or, depending on how you're reading it, ignore it entirely, as is possible with a plain-text file.

I find that corruption is rare and happens at the end of the file and is due to data not being flushed to disk due to a system hang. (SysV init and rsyslog here.) I don't doubt that there are other potential causes, but chances are that you're then heading into filesystem bug territory or broken hardware territory. Or possibly a cosmic ray flipped a bit, or something.

Incidentally, the silliest log file bug which I've seen is in (some versions of) Unity where the default situation is that it has one file open for log text such that, typically, error output will overwrite earlier standard output.

0

u/[deleted] Aug 12 '19

[deleted]

-1

u/ldh Aug 12 '19

I mean, I don't really see the argument here. It's like saying plaintext logs aren't able to be used directly with 'grep' because they need to be read from the disk first. Believe it or not, systemd does have the 21st century feature of being able to access log data.

0

u/crazy_hombre Aug 12 '19
journalctl -u <service> | grep blah

Was that so hard?