Closed hos7ein closed 4 years ago
Hi @hos7ein
There are several ways of doing this, depending on what you require. By default, docker saves its logs to a JSON file. To find this, you can do
docker inspect --format='{{.LogPath}}' <container id>
For example, when I run a CrateDB container:
$ docker inspect --format='{{.LogPath}}' c8e1656862bd
/var/lib/docker/containers/c8e1656862bdec110a1f177ca89d32c8497d0bb4796157720ad17b67b815d23b/c8e1656862bdec110a1f177ca89d32c8497d0bb4796157720ad17b67b815d23b-json.log
The path given there will be the path to the log file, which contains lines like this:
$ cat /var/lib/docker/containers/c8e1656862bdec110a1f177ca89d32c8497d0bb4796157720ad17b67b815d23b/c8e1656862bdec110a1f177ca89d32c8497d0bb4796157720ad17b67b815d23b-json.log
{"log":"[2020-03-11T10:31:17,447][INFO ][o.e.e.NodeEnvironment ] [L'Aiguille Rouge] using [1] data paths, mounts [[/data (/dev/mapper/luks_root)]], net usable_space [375.7gb], net total_space [467.6gb], types [ext4]\n","stream":"stdout","time":"2020-03-11T10:31:17.449891941Z"}
{"log":"[2020-03-11T10:31:17,450][INFO ][o.e.e.NodeEnvironment ] [L'Aiguille Rouge] heap size [512mb], compressed ordinary object pointers [true]\n","stream":"stdout","time":"2020-03-11T10:31:17.450306456Z"}
{"log":"[2020-03-11T10:31:17,451][INFO ][o.e.n.Node ] [L'Aiguille Rouge] node name [L'Aiguille Rouge], node ID [yoKpWGLmRROUskgE2W8-5Q]\n","stream":"stdout","time":"2020-03-11T10:31:17.451685403Z"}
{"log":"[2020-03-11T10:31:17,462][INFO ][o.e.n.Node ] [L'Aiguille Rouge] version[4.1.3], pid[1], build[e837e38/2020-03-05T15:39:20Z], OS[Linux/5.4.23-1-lts/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/13.0.1/13.0.1+9]\n","stream":"stdout","time":"2020-03-11T10:31:17.46310394Z"}
{"log":"[2020-03-11T10:31:17,696][INFO ][i.c.plugin ] [L'Aiguille Rouge] plugins loaded: [jmx-monitoring, enterpriseFunctions, lang-js] \n","stream":"stdout","time":"2020-03-11T10:31:17.6963748Z"}
You could also stream the docker logs to a file of your choice, like this:
docker logs -f c8e1656862bd &> cratedb.log
The -f
flag means the process will continue to log as the container runs, and the &>
means that it will both collect stdout and stderr messages.
If you wanted a more sustainable solution, you could create your own log4j2 configuration to save the logs to a file. The current, default configuration that the docker container uses can be found here: https://github.com/crate/crate/blob/master/app/src/main/dist/config/log4j2.properties
The documentation for path.logs
and path.conf
here would be useful, as would our documentation on application logging.
Does this solve your issue, @hos7ein ?
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
I run crate in docker, but I want to know how can I save log into the file? Because I just can see the log in the docker console.
Thank you,