GithubHelp home page GithubHelp logo

Add log rotation support about watchman HOT 9 OPEN

facebook avatar facebook commented on April 24, 2024
Add log rotation support

from watchman.

Comments (9)

 avatar commented on April 24, 2024

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

from watchman.

wez avatar wez commented on April 24, 2024

This is doable in most common cases; if we were passed a log file name argument, then we can periodically check the size and rotate.

from watchman.

qmaruf avatar qmaruf commented on April 24, 2024

I am interested to work on this feature. @wez Could you please suggest me from where should I start? I've built _watchman_ on my machine.

from watchman.

wez avatar wez commented on April 24, 2024

@qmaruf yep, the high level idea is that we'd want to rotate the log file. This is typically implemented in one of two ways:

  1. External software that manages log files can rename the current log file to a new name, then send some kind of signal to the service to tell it to re-open its log file
  2. Modify the service itself so that it has some kind of rotation policy.

We can support both of these things. The high level plan is:

  1. Add a function that can reopen the log file. This is logically as simple as closing the old log file handle and then opening the configured log file again. The existing code for opening the log file is towards the top of main.c; it should be moved into log.c. Care should be taken to ensure that we don't lose log events while making this switch.
  2. Add a watchman command that will trigger the log file to be re-opened. This will facilitate controlling log file rotation via software like logrotate; it would just run watchman log-reopen
  3. Add a configuration option that specifies:
    1. how often to check the log file size in seconds
    2. the maximum size
  4. If size checking is enabled (the checking interval is non-zero), every interval seconds, compare the size. If the size is larger than desired, rename the log file by appending the current unix timestamp to the log file name and then reopen the log file.

I consider the following things to be non-goals for watchman; our focus is on answering questions about the filesystem rather than re-implementing features that exist in other widely deployed software:

  1. Configuring an alternative or more flexible way of naming the moved log files
  2. Limiting the number of re-opened log files (I'm on the fence about this, but am leaning towards saying that the user can script cleaning this up for themselves, outside of watchman. Other software exists with the sole purpose of performing this kind of cleanup)

from watchman.

qmaruf avatar qmaruf commented on April 24, 2024

Is there any way to print something in console using _printf()_ while watchman is running, for debugging purpose? I am using _watchman --server-encoding=json --persistent log-level debug_, but it only prints log info. I need to understand the sequence of execution.

from watchman.

wez avatar wez commented on April 24, 2024

you can use w_log(W_LOG_ERR, "format %s\n", "foo") to log to the log file at ERR level.
You can run: watchman --foreground --logfile=/dev/stdout to run in the foreground and have the log file go to your terminal. You can use the -v option to change the default log level.

from watchman.

qmaruf avatar qmaruf commented on April 24, 2024

@wez What does watchman do after w_event_set()? AFAIU, w_event_set() is called after enqueuing log message in client queue. I am looking for the code where client is dequeued and log message is written to file.

from watchman.

wez avatar wez commented on April 24, 2024

I'm not sure I understand your question. The client responses are de-queued dispatched here: https://github.com/facebook/watchman/blob/master/listener.c#L495 but that is completely unrelated to the log file related functions that are in log.c

from watchman.

qmaruf avatar qmaruf commented on April 24, 2024

I thought message is being written to log file after dequeuing from client. I planned to check log size before writing to it so that we could avoid checking its size continuously whenever we don't need to .

from watchman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.