gregwebs / Shelly.hs

Haskell shell scripting
BSD 3-Clause "New" or "Revised" License
418 stars 88 forks source link

print_commands cannot be captured by custom loggers #129

Open shouya opened 8 years ago

shouya commented 8 years ago

The following code demonstrates the problem:

main = shelly $ log_stdout_with myLogger $ print_commands True $ do
  run "ls" []

myLogger text = print $ "[OUT] " <> text

ls is printed but without [OUT] prefix, this means myLogger is not handling command printing.

Is it possible to capture all the commands like it for the outputs?

Why do I need this feature:

I'm writing a program that will run some shell commands and send all shell activities to a logger. Unfortunately at the time I can only capture stdout/stderr. The printed commands will be very helpful to locate errors and to trace what happened.

gregwebs commented 8 years ago

I think you would just need to change this line: https://github.com/yesodweb/Shelly.hs/blob/master/src/Shelly.hs#L1201 to use sPrintStdout state.

shouya commented 8 years ago

In fact the command executed got print out to the console, except that this output can't be captured. So perhaps changing that line to sPrintStdout state ain't very useful.

I guess perhaps I should change echo cmdString to something else?