Skip to content

Watchman should escape color codes in environment variables before logging them #47

Closed

Description

@mganjoo

Some of my environment variables contain ASCII color codes (notably, the LESS_TERMCAP_* variables). Watchman logs these, along with other environment variables, when a file trigger is activated, but doesn't seem to escape them, which results in entire blocks of the log output being displayed in random colors when I tail the log. Here's an example of a problematic log line which triggers a color change:

1407265155: tid=12767232 envp[49] LESS_TERMCAP_mb=^[01;31m

Shouldn't watchman be escaping/stripping such codes?

Activity

  1. wez commented on Aug 6, 2014

    @wez
    Contributor

    The log is there primarily to figure out what is broken, and I'd rather avoid stripping for two reasons:

    • it will drive up the cost of logging
    • it can mask potential problems by obscuring what was actually being set.

    Tailing the log file should be a rare event; is there something that is causing you to do this frequently?

  2. mganjoo commented on Aug 6, 2014

    @mganjoo
    Author

    So my use case is to scp a jar file to a server every time it's successfully built. I want to see whether that is happening correctly, and as a quick solution, I simply tail the watchman log (while scp -v is set, so that I can see what the command is up to). I guess that's not the idiomatic way to do things, and that I should write a command that handles its own logging instead?

  3. wez commented on Aug 6, 2014

    @wez
    Contributor

    One of the things that people find awkward about triggers is that they are headless and continue running even when your terminal session is over. This is a feature but is a bit different from most of the other watchers out there.

    One of the things on my mental TODO (although I could have sworn I had it transcribed in an issue here) is to have a session-oriented trigger mode, where you would do something like:

    $ watchman fg-trigger <pattern> -- <command>
    

    and that process would subscribe to the watchman service and spawn in your terminal session whenever matching files are changed. It could then log that it was running. Pressing CTRL-C would stop it from triggering, just like a regular unix command.

    Since we don't have this today, another suggestion for you is to write a little wrapper script around the log subscriber command:

    $  watchman --server-encoding=json --persistent log-level error | grep scp
    

    or do something a bit more fancy to munge and format the json records as you prefer. You can play with the log level to adjust verbosity.

  4. mganjoo commented on Aug 7, 2014

    @mganjoo
    Author

    That makes sense. The log wrapper suggestion seems like it would serve my purposes. Thanks!

  5. wez commented on Aug 10, 2014

    @wez
    Contributor

    I'll close this out as it doesn't require any code change in watchman itself; Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions