Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Ability to clear log history #1083

Closed
djessup opened this issue Mar 9, 2015 · 158 comments
Closed

Feature: Ability to clear log history #1083

djessup opened this issue Mar 9, 2015 · 158 comments

Comments

@djessup
Copy link

djessup commented Mar 9, 2015

A feature I've thought would be useful since originally using Fig, and now Compose would be the ability to clear the log history for Composed-managed containers. Long-running or "chatty" containers can end up with a lot of log noise that may not be wanted.

I'd expect a command like the following would solve the problem:
$ docker-compose logs --clear [service]

@dnephin
Copy link

dnephin commented Mar 13, 2015

I don't think that is a feature supported by the docker daemon. Looking at the api docs, the only option would be to truncate the returned logs to a limited number of lines per container:

https://docs.docker.com/reference/api/docker_remote_api_v1.17/#get-container-logs

@metal3d
Copy link

metal3d commented Apr 9, 2015

👍 for this issue. I actually use compose to develop a website in Golang, Mongodb and nginx... 5 days after begining I have a long logs that becomes to be worrying. Each time I restart containers append many lines to the log.
@dnephin I don't understand if you give a solution (that I don't understand :)) or if you propose to check if it's possible with api. Sorry for my bad english.

@thaJeztah
Copy link
Member

Docker 1.6 will add support for logging drivers, see moby/moby#10568 (currently; JSON, syslog and "none") work is in progress for basic log-rotation; moby/moby#11485

@metal3d
Copy link

metal3d commented Apr 13, 2015

Good to hear that, thanks a lot :)

@djessup
Copy link
Author

djessup commented Apr 17, 2015

Thanks for the background and update on Docker 1.6 - looking forward to it!

chernjie added a commit to chernjie/elk that referenced this issue Apr 20, 2015
chernjie added a commit to chernjie/elk that referenced this issue Apr 20, 2015
@sgarbesi
Copy link

docker logs -c (clear) <container> would be great.

+1

@baptistedonaux
Copy link

+1 Really important

@egyptianbman
Copy link

Holy cow, I just sat through several minutes of logs to get to the end. I'd really appreciate this as well for the sake of not having to rebuild containers constantly.

@jghibiki
Copy link

+1

3 similar comments
@vronin
Copy link

vronin commented Sep 15, 2015

+1

@junajan
Copy link

junajan commented Sep 17, 2015

+1

@knutole
Copy link

knutole commented Sep 18, 2015

👍

@Rodeoclash
Copy link

+1

@nafg
Copy link

nafg commented Sep 21, 2015

+2

@FnTm
Copy link

FnTm commented Sep 21, 2015

+1

@dmage
Copy link

dmage commented Sep 21, 2015

Just for the record, with Docker 1.8 and docker-compose 1.4 there is already exists a method to limit log size using https://docs.docker.com/compose/yml/#log-driver and log-opt max-size:

  log_driver: "json-file"
  log_opt:
    max-size: "100k"
    max-file: "20"

@knutole
Copy link

knutole commented Sep 21, 2015

@dmage Thanks, exactly what I need.

@OlivierCuyp
Copy link

+1000

@sheyman
Copy link

sheyman commented Oct 11, 2015

+1 would LOVE this

@joegoggins
Copy link

+1

@Rodeoclash
Copy link

@dmage solution works great for us. Those others who are +1ing this, what is wrong with the solution that he's given?

@rosskevin
Copy link

@Rodeoclash - I think one use case for this is reuse of a given set of containers for a new run i.e. CI test run. The old logs are irrelevant to the new run, so a clear prior to the next command would clear up confusion.

@SpeCT
Copy link

SpeCT commented Oct 14, 2015

+1

@ballinette
Copy link

+1, same need as @rosskevin

@dnephin
Copy link

dnephin commented Oct 19, 2015

Ok, to recap:

Going to close this since it's already support or tracked in other issues.

@ccamacho
Copy link

+1

1 similar comment
@MPJHorner
Copy link

+1

@WhiteBearSpirit
Copy link

WhiteBearSpirit commented Feb 9, 2018

I made a simple script docker_clear_log.sh:
sudo truncate -s 0 $(docker inspect --format='{{.LogPath}}' $1)
Usage: ./docker_clear_log.sh [Name-or-ID]
Should work if you have sudo rights and log_driver: "json-file" setting for your docker (default).

@gsugambit
Copy link

gsugambit commented Mar 5, 2018

+1

I also tried to temp solution and it appears to work

@educatedwarrior
Copy link

educatedwarrior commented Jun 23, 2018

The original issue was never resolved and the issue was closed anyway. Interesting. @djessup , how do you like those apples?

@dhakehurst
Copy link

would still be nice to have a docker-compose logs --clean

@linvi
Copy link

linvi commented Oct 12, 2018

Why has this issue been closed without even a comment when the issue in itself has not been solved?

@Ghoughpteighbteau
Copy link

@linvi

When I came to this thread, the closing comment had been folded into other comments. It's right here:

#1083 (comment)

I think they're hoping to cover this particular use case through indirect means. Mention you're particular use case and how it's not covered, and it might help the ticket be re-opened. Worst case, someone might point out an easy way to get what you want :D

ewjay pushed a commit to ewjay/fapi-conformance-suite that referenced this issue Oct 30, 2018
'docker-compose restart server' seems to replay all the logs, which on
my mac had reached 125M and it took quite a while to replay that much
data to the terminal.

Found on:

docker/compose#1083 (comment)

and documented here:

https://docs.docker.com/config/containers/logging/json-file/#options
@MartinNiederl
Copy link

Any updates?

@FelixFurtmayr
Copy link

when there is a log, we should be able to clear it in a simple way.

would be really nice, if you could build the command into it. this seems not hard.
thousands of people would be very happy not having to scroll through everything.

@FelixFurtmayr
Copy link

If you use docker-compose, use lazydocker for viewing logs. Then there is then no need to delete logs. You get live logs and start with the latest logs. This helps very much with debugging.

grafik

https://github.com/jesseduffield/lazydocker
You can install it with one line and it is a good monitoring tool. It is a pitty that people are not so reasonable to understand that a "delete log" function is a good thing.

But the workaround with lazy docker does it for me. Thank you jesseduffield for giving us the possibility to be lazy with your monitoring tool :-)
Maybe consider donating to lazydocker if this makes debugging/monitoring for you also easier.
And for you docker developers / maintainers: why is the interface from docker not like that?
Docker is pretty awesome, but have a look at lazydocker; there is room for improvement.

@GF-Huang
Copy link

+2147483647

@kagansari
Copy link

+49324893

@bf
Copy link

bf commented Nov 21, 2020

This is such a central problem with UX of docker-compose, I wonder why it has not been resolved. Every time I run docker-compose up, some of the new logs are put on the top of super old logs from 5 starts ago. What is this?

@GF-Huang
Copy link

This issue should be re-open.

@ell1e
Copy link

ell1e commented Nov 22, 2020

I would love to use this as well. Why can't there be a simple docker-compose logs --clean-logs <service>?

@srinitude
Copy link

Echoing everyone here lol

@eon01
Copy link

eon01 commented Feb 19, 2021

A simple workaround for me is using docker-compose up --force-recreate

@srinitude
Copy link

@eon01 Awesome hack! Thanks for sharing

@GF-Huang
Copy link

7 years passed.

@reesericci
Copy link

Please add this!!!

@rentianxiang
Copy link

rentianxiang commented Sep 20, 2022

Please add this! And reopen this issue!

@julianoamg
Copy link

sudo sh -c "truncate -s 0 /var/lib/docker/containers/**/*-json.log"

@julianoamg

This comment was marked as off-topic.

@ajs6f
Copy link

ajs6f commented Nov 27, 2023

+1

@PavelNiedoba
Copy link

PavelNiedoba commented Feb 12, 2024

It would make even more sense if you can

docker compose logs clear [all | since | keep lines xxx | you name it]

so it cleans logs for whole stack

also archiving in production environments would be nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests