Skip to content

Make output of stack path independent of logging. #604

Closed

Description

@ntc2

The output of stack path is produced using Control.Monad.Logger.logInfo. This makes stack path --<some specific path> unusable, since the output can't be separated from other log output.

Expected

I'm writing script that copies Stack-produced binaries. I would like to do e.g.

cp "$(stack path --local-install-root)"/bin/saw tmp/release/bin

Actual

However, I'm exporting STACK_YAML -- we build against both GHC 7.8 and 7.10 -- and so the output of stack path --local-install-root includes a warning on the first line which causes the cp to fail:

Getting project config file from STACK_YAML environment
/home/conathan/v/saw-script.git/.stack-work/install/x86_64-linux/lts-2.15/7.8.4

Note that using --verbosity <verbosity level> doesn't help, since the warning and the path are both printed using logInfo, so you get both or neither.

Ideas for fixes

In any case, the regular output of the stack path command should not be produced using logInfo. So, change $logInfo to T.putStrLn at

$logInfo
.

I would also suggest that log messages go to stderr by default. If you have a reason for sending log messages to stdout, then --verbosity silent could still be used to suppress them, so this is not essential.

Workaround

In the mean time I could reimplement stack path --local-install-root in terms of stack path:

stack --verbosity info path | sed -ne 's/local-install-root: //p'

Another workaround is to do stack --stack_yaml=$STACK_YAML path --local-install-root, but that will break if I stop exporting STACK_YAML later.

Activity

  1. mgsloan commented on Jul 16, 2015

    @mgsloan
    Contributor

    In any case, the regular output of the stack path command should not be produced using logInfo. So, change $logInfo to T.putStrLn at

    $logInfo
    .

    Sounds like a good change to me! Feel free to make a PR :D

  2. chrisdone commented on Jul 16, 2015

    @chrisdone
    Member

    Errors and warnings were changed in the last couple days to go to stderr by default. Did you try recent master?

  3. borsboom commented on Jul 16, 2015

    @borsboom
    Contributor

    We should probably suppress the Getting project config file from STACK_YAML environment message when stack is not running in a terminal, like is done here:

    when (getTerminal env) $

  4. ntc2 commented on Jul 16, 2015

    @ntc2
    ContributorAuthor

    @mgsloan: OK. Seems silly to make a pull-request for a one line change, but I'll do that and also try rewording the CONTRIBUTING.md a little in hopes of making well-intentioned people like me submit better error reports in the future (see below) :)

    @chrisdone: no, I was using 0.1.2.0; sorry I did not include that info. Interestingly, you guys ask for this info explicitly in the CONTRIBUTING.md, which I thought I read, but my takeaway was to add some header sections ("Expected", "Actual") :P I think the problem was that there's a lot of example text which my brain decided was irrelevant and ignored.

    @manny-fp: that sounds like a great idea!

  5. mgsloan commented on Jul 16, 2015

    @mgsloan
    Contributor

    @ntc2 True, I'm just encouraging contribution! We're trying to keep the barrier to contribution as low as possible. We can give you commit access if you'd like to commit such changes directly to master.

  6. ntc2 commented on Jul 16, 2015

    @ntc2
    ContributorAuthor

    @chrisdone: using current master logging still goes to stdout, e.g.:

    $ git log -1
    commit 2723b3567e44725b176c35786a5e11db454d183e
    Author: Chris Done <[email protected]>
    Date:   13 hours ago
    
        hindent reformat
    
    $ stack --version
    Version 0.1.2.1, Git revision 2723b3567e44725b176c35786a5e11db454d183e
    
    $ (export STACK_YAML=stack.yaml && stack path --local-install-root) | wc -l
    2
    
    $  (export STACK_YAML=stack.yaml && stack --verbosity debug path --local-install-root) | wc -l
    8
    

    Of course, those commands only produce INFO and DEBUG level log messages.

    (EDIT: I pasted the wrong commands; the output is the same.)

  7. ntc2 commented on Jul 16, 2015

    @ntc2
    ContributorAuthor

    @mgsloan: no worries, I really appreciate how responsive you guys are; I just meant it would be a lot quicker for one of you who already has the code base to spend 1 minute making this change. But now that I have the code I will also look into changing log messages to go to stderr instead :) I'll stick with the pull request for now; that will ensure I don't make any changes you guys don't like.

  8. ntc2 commented on Jul 17, 2015

    @ntc2
    ContributorAuthor

    @mgsloan: I created a pull request: #615. I'm not sure you will like the "make all log messages go to stderr" change. If not, could you explain why you guys want to send log messages stdout?

    @chrisdone: so, ERROR and WARNING level log messages were going to stderr, like you said. But, the STACK_YAML warning that causes the problem is an INFO level warning, and those were still going to stdout. Another solution to my specific problem would be to send the STACK_YAML warning to level WARNING instead, but I'm still concerned about the general problem of unpredictable stdout due to logging.

  9. radix commented on Jul 17, 2015

    @radix
    Contributor

    +1 for making all logging out-of-band (i.e. go to stderr), that nicely separates intended, crafted output from everything else.

  10. mgsloan commented on Jul 17, 2015

    @mgsloan
    Contributor

    @ntc2 Cool, thanks for making a PR - we're on board with logging going to stderr.

  11. added a commit that references this issue on Jul 17, 2015
  12. mgsloan commented on Jul 17, 2015

    @mgsloan
    Contributor

    Merged!

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