DISQUS

DanNorris.com: On handling logging in a script

  • Nigel Thomas · 1 year ago
    Dan

    Another approach (which also works on Windows) is to place the commands you want to log into a bracketed section

    (
    commands to be logged
    more commands to be logged
    ) > $LOG

    This has the added benefit on *nix that you can easily tee and grep the output. So you can log *everything* to a file, but filter out (say) significant progress and error messages. I tend to start my messages with == (the more equals signs, the more important) and then you can filter messages by how many == they have:

    (
    commands
    ) | tee $log | grep "^==="

    Of course on *nix you can also redirect stderr at the same time in the usual way(s) eg:

    (
    commands
    ) >2&1 >$LOG

    I think using brackets (braces) like this is easier to read - and you can nest the brackets too. Just make sure you match brackets properly.

    Regards Nigel
  • Dan · 1 year ago
    That's a nice way to handle it. I don't agree that it makes the script code easier to read with lots of parens hanging around, but I still think it's a useful technique--I like the filtering too.

    Thanks for the nice tip!
  • billy · 1 year ago
    no kilt no way. too cold, the boyz will freeze.