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

The log file stops recording after it has been modified by a third-party process #19

Closed
ConstCh opened this issue Mar 29, 2019 · 10 comments

Comments

@ConstCh
Copy link

ConstCh commented Mar 29, 2019

To reproduce the error, try the following test case:

  • start docker-logger
  • open log file for any container via vim
  • edit log file
  • save changes
    and then log file stops recording
    and i don't have any error in docker-logger.log
@umputun
Copy link
Owner

umputun commented Mar 29, 2019

I'm not sure if this behavior is a sign of any error. Is there a real use case where you need to modify log file and if so - what exactly you expect from the logger in this situation?

@ConstCh
Copy link
Author

ConstCh commented Mar 29, 2019

Logs should continue to write after the file is released

Editing a log file is just an example of lock.

@umputun
Copy link
Owner

umputun commented Mar 29, 2019

the question is why anyone even needs to open the log file for write and modify it. And what are other practical examples of any third-party application locking logs?

@ConstCh
Copy link
Author

ConstCh commented Mar 29, 2019

I just accidentally open log file for edit in shared folder, and eventually lost a few hours of logs before restarting docker-logger container

@ConstCh
Copy link
Author

ConstCh commented Mar 29, 2019

Additional case... You can delete the log file and after that a new file will not be created.

@umputun
Copy link
Owner

umputun commented Mar 29, 2019

I don't think this issue has anything to do with docker-logger implementation. Most likely it is a part of the (un)expected behavior of lumberjack used by docker-logger to handle files, rotation and so on. I don't see it as a good enough reason to replace or fork lumberjack. However, if you think such behavior is a bug and should be fixed, pls report to lumberjack repo.

@umputun umputun closed this as completed Mar 29, 2019
@mikhail-angelov
Copy link

I have the same issue, time after time logs stops to collect, I agree it most likely lumberjack issue

since the is no workaround for this issue
I recommend to use other solution wich ack similar as this logger

https://docs.fluentd.org/
it allows to collect logs into file
this is example setup

#docker-compose.yaml
version: '3.7'

services:
  fluentd:
    image: fluent/fluentd:v1.15-1
    container_name: fluentd
    hostname: fluentd
    restart: unless-stopped
    volumes:
      - ./fluentConf:/fluentd/etc
      - ./logs:/fluentd/log
    ports:
      - "24224:24224"
      - "24224:24224/udp"
    networks:
      - webnet

  nginx:
    image: umputun/nginx-le:latest
    container_name: nginx
    hostname: nginx
    restart: unless-stopped
    networks:
      - webnet
    logging:
      driver: fluentd
      options:
        fluentd-async: "true"
        tag: app.nginx
    volumes:
      - ./nginx/ssl:/etc/nginx/ssl
      - ./nginx/services.conf:/etc/nginx/services.conf
      - ./nginx/.htpasswd:/etc/nginx/.htpasswd
    ports:
      - "80:80"
      - '443:443'
    environment:
      - TZ=UTC
      - LETSENCRYPT=true
      - LE_EMAIL=test@gmail.com
      - LE_FQDN=test.xyz
networks:
  webnet:

config

#fluentConf/fluent.conf
<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

<filter app.**>
  @type record_transformer
  <record>
    time ${time}
  </record>
</filter>

<match app.**>
  @type copy
  <store>
    @type file
    path /fluentd/log/%Y%m%d-${tag}
    append true
    compress gzip
    <format>
      @type csv
      force_quotes false
      delimiter \t
      fields time,source,log
    </format>
    <buffer time,tag>
      flush_mode interval
      flush_interval 1d
    </buffer>
  </store>
  <store>
    @type stdout
  </store>
</match>

CONS:

  • a bit more complicated to configure
  • third party dependency

PROS:

  • looks like more stable
  • have more options to extend (e.g. copy logs to S3 or ELK)

@glmars
Copy link

glmars commented Sep 2, 2022

@mikhail-angelov additional CONS:

  • the docker logs command is not available for this logging driver

@mikhail-angelov
Copy link

@mikhail-angelov additional CONS:

* the docker logs command is not available for this logging driver

I'm not sure about this cons
e.g. this command shows logs

docker logs -f nginx

@glmars
Copy link

glmars commented Sep 5, 2022

this command shows logs

Sorry, couldn't check this I have quoted docker docs: https://docs.docker.com/config/containers/logging/fluentd/

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

No branches or pull requests

4 participants