0

I am using ConsoleAppender for logging in my Java application. ConsoleAppender writes to the System.out which is stdout in case of Linux.

Can someone help me understanding where does stdout logs go and how much is the memory assigned to it.

I need to know this because all my logs to stdout are not being picked by filebeat to put in the elastic search index.

Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
Anshul Sharma
  • 1,018
  • 3
  • 17
  • 39

1 Answers1

2

Can someone help me understanding where does stdout logs go

Usually stdout simply goes into the buffer of your shell which is usually not buffered/recorded to any file. I say usually because I am sure that there are some special systems & Linux distributions that can handle things differently. For the rest, I assume that you use a "common Linux desktop or server distribution."

However, what you can do is redirecting stdout to a file.

I assume that you launch your application similar to this:

java -jar myapp.jar

Your application outputs to stdout which allows you to see the output in the terminal.

On Linux (I'd say most Unix systems), you can simply redirect the stdout (and optionally stderr) to a file like this:

java -jar myapp.jar > output.txt

A file named output.txt should then be created on your system. If you still need "real time user feedback" you can simply do something like

tail -f output.txt

to continiously print the contents of output.txt to stdout.

how much is the memory assigned to it.

Your output.txt file will grow until you run out of disk space. You can use your distributions log rotation system to limit the size of the file. FreeBSD uses newlogsys(8). I am sure that the Linux distribution of your choice comes with a similar system already in place.

Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
  • https://stackoverflow.com/users/1414496/joel-bodenmann in the first case where redirection of application log is not happening, it will go to buffer, can you tell me what is the size of that buffer. – Anshul Sharma Nov 15 '19 at 11:55
  • This is depending on the implementation. You might find this question helpful: https://stackoverflow.com/questions/10904067/in-c-whats-the-size-of-stdout-buffer – Joel Bodenmann Nov 15 '19 at 12:14
  • Furthermore, if your system design relies on knowing this information then you should most likely consider changing your design. Something as simple as an `stdout` redirection to a file as described in my answer is not only very easy to do, but also intended use of the underlying operating system and the other involved components. – Joel Bodenmann Nov 15 '19 at 12:32