immortal / immortal

⭕ A *nix cross-platform (OS agnostic) supervisor

Home Page:https://immortal.run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question - log throughput

alexzaytsev-newsroomly opened this issue · comments

When i run my app via immortal with yml config, if i don't specify the log option, i don't see any logs in my console, apart from process starts and exists.
Is it possible to have the logs sent to the console from a running process?

Does Your app writes to stdout or stderr ?

stdout

@nbari those solutions imply that you know the pid? which i won't know until immortal has started it, so i guess i'd need to do something like ./immortal -c somewhere && && tail -f /proc/$(./immortalctl | grep 'mycommand' | awk '{print $3;}' )/fd/1?

Hi @alexzaytsev-newsroomly if you want to see stdout of your application within the same terminal/console then you just launch it without using immortal, otherwise your app/program will be detached and demonized so that if you close your terminal your process still up and running.

If I may ask, what are you trying to do?

@nbari i have the app which runs inside docker. I use immortal to bootstrap the app, so that if it crashes inside the container it is restarted instantly (rather than my delayed healthcheck do that). After the app has started, all the logging is channeled appropriately (to slack, for example). However, in development the app may fail to load before the internal logging is initialized. Normally, i would just docker logs and see the issue. However, under immortal, when i do docker logs all i see is the 'process PID exited with code such and such' which is not very helfpul.

Hi @alexzaytsev-newsroomly don't know if this may help but you could pass any program to handle the stdout output for example:

cmd: your-app
logger: logger -t test

In this case logger: is going to send all the output to the program logger

Closing this for now, feel free to open it if needed.

@nbari this sort of worked for one use case, but not so much for another - we want to monitor logs in AWS cloudwatch, and unfortunately we can't just ship them there.

I am not a Go developer, but ti seems if we add a log.printf on line 30 here: https://github.com/immortal/immortal/blob/3e1a024327ecd437a801f80acd89572b7cd6b779/logger.go

We might be able to get what we want. Would you be able to confirm?

Essentially, i want every message that is currently logged to a logfile (if one is specified in yml config) to be printed on the screen (default immortal console session).

Thank you.

hi @alexzaytsev-newsroomly modifying the code won't work, as explained before, but if you explain in detail what tool you are using to collect your logs, probably I could find something that may help. There are many options, for example, you could probably just use the tee command:

logger: tee -a /tmp/test.log

That will append/write to /tmp/test.log while printing to stdout

Alrighty, i was able to get what i wanted by creating a symlink for the /proc/1/fd/1 e.g. like so ln -sf /proc/1/fd/1 /var/log/whatever.log and then specifying this as the log file in the immortal config.

Quick question: If i omit the age, num and size parameters, does it mean that immortal won't try to trim the file and just keep writing to it indefinitely?

Hi @alexzaytsev-newsroomly you could set age to 0 (size defaults to 0) that will avoid rotating the file or you could totally avoid writing to a file by using the logger option like mentioned before, in case you don't have the tee command you could either use cat this will save you from creating a symlink.

@nbari i tried cat before and it output nothing.

What about tee ?

The logger will do something like:

 echo "foo" | cat

of

echo "foo" | tee

@alexzaytsev-newsroomly this should work to avoid log rotation:

log: 
    file: /path/to/your/file.log

By not declaring age, num, size (I need to improve docs about this)

@nbari nope, tee is the same as cat, nothing...

Hi @alexzaytsev-newsroomly I just created this so that I don't forget: #36 please feel free to add/extend if required.

@nbari i don't know if you find my above example useful/warranted enough, but that's something that you can also include along the lines of: when running in docker, you may hit this issue, here's how to solve it. Just a thought. Otherwise - many thanks, immortal serves us well!