erlware / relx

Sane, simple release creation for Erlang
http://erlware.github.io/relx
Apache License 2.0
697 stars 231 forks source link

best practice question on Logging #762

Open eugene-panferov opened 4 years ago

eugene-panferov commented 4 years ago

a release made by relx automagically logs everything the program spits into std_out -- the result is quite good, rotated, and human-readable, and with little effort on my part i can make it machine-readable.

meanwhile, in OTP21 appears a very advanced kernel/logger facility.

which method should i prefer? what circumstantial issues should i consider in order to answer my question?

tsloughter commented 4 years ago

When you say it is rotated, do you mean you are using start instead of foreground to run your release?

My suggestion would be to use the new OTP logger with a stdout handler and the foreground command to start the release. It will write to stdout and not files.

The fact that you mentioned rotation is why I wondered if you actually wanted it in files though? I'd still leave that up to something like systemd and use the above setup of logger and foreground.

eugene-panferov commented 4 years ago

pardon, i see no point in foregrounding a server, what am i missing?! seriously. i am now more confused that i was before. why are you suggesting to kill the feature that is necessary, which is saving to filesystem and rotation.

tsloughter commented 4 years ago

So you are using start?

The reason I suggest foreground is that people usually are using something like systemd or are running in a docker container. In those cases foreground is the best way to run a release. If start works for how you run releases then that is fine and you should continue with it, and yes, use the new OTP logger which if configured to write to stdout will also go to the files you are getting from using start.

eugene-panferov commented 4 years ago

does it mean that "io:" operations are slower (being synchronous) than the "logger:" calls (when they are asynchronous)? is there a bottleneck of any sort in the relx's automagic with std_out? aren't we hitting the same limitations if using kernel/loggers to std_out which then is treated by the same automagic as before? isnt it just adding some complexity to get the same result?

tsloughter commented 4 years ago

Note there is no magic and it is not a relx feature, start simply runs with http://erlang.org/doc/man/run_erl.html

One reason not to use run_erl is that it fsyncs output to disk on every line it gets which can be a slowdown. So using foreground and letting the init system handle the logs can be better for some. Plus using foreground means the init system can easily track the running release, no need for a pid file and all that.

Use of logger instead of io is because it has handlers that can format and decorate your logs with more information (and other features like filtering, log levels and what not).