Skip to content

Differentiate sls invoke response from logging to allow piping result #4675

Closed

Description

@mvayngrib

This is a Feature Proposal

Description

problem:
when you run sls invoke, both the invocation response and logs are written to the console with console.log (stdout). This makes it hard to differentiate the invocation response from logging, and makes piping the command impossible.

potential solutions:

  • log to stderr, write the invocation response to stdout.
  • accept an --output option, and write the response to the provided file path

Activity

  1. changed the title [-]differentiate invoke response from invoke logging to allow piping result[/-] [+]differentiate sls invoke response from loggins to allow piping result[/+] on Jan 22, 2018
  2. changed the title [-]differentiate sls invoke response from loggins to allow piping result[/-] [+]differentiate sls invoke response from logging to allow piping result[/+] on Jan 22, 2018
  3. HyperBrain commented on Jan 22, 2018

    @HyperBrain
    Contributor

    We should fix the correct output stream for errors to stderr (see my comment in #4673 )
    However, the log output belongs to one or the other depending on the log level, e.g. informational logs belong to stdout while error logs do not.

    As the results that are logged are in fact data outputs, they should go into stdout (as is), but additionally having --output|-o to redirect the data output would be very beneficial.

  4. mvayngrib commented on Jan 22, 2018

    @mvayngrib
    Author

    @HyperBrain i agree, writing all logs to stderr would be morally wrong :) my vote's for --output as well.

    in the current code, invoke output isn't handled in any centralized fashion - there are just console logs sprinkled around. Are there are plans to? It doesn't seem hard to handle --output for invoke, and for invoke local on Node.js. However, the output from local python and java lambdas doesn't seem differentiated

  5. changed the title [-]differentiate sls invoke response from logging to allow piping result[/-] [+]Differentiate sls invoke response from logging to allow piping result[/+] on Feb 13, 2019
  6. huonw commented on Jan 5, 2021

    @huonw

    We're hitting this somewhat, we're invoking a function and expecting a JSON response, but there's a serverless warning, so the stdout "JSON" is:

     Serverless Warning --------------------------------------
     
      A valid environment variable to satisfy the declaration 'env:XYZ' could not be found.
     
    {
        "success": true
    }

    And this is of course not valid JSON, breaking our later processing. We're fixing the warning, but a pipeline doing something else isn't our preferred place to be informed of a warning.

    However, the log output belongs to one or the other depending on the log level, e.g. informational logs belong to stdout while error logs do not.

    I'm not convinced of this: I think the stderr name is deceptive and it shouldn't just be "error logs go here", but everything that isn't part of the data output. stdout would be completely junked up by INFO and DEBUG level logs (when enabled), even if WARNING and ERROR level logs are going to stderr.

  7. medikoo commented on Dec 7, 2021

    @medikoo
    Contributor

    Closing as it's fixed with #9860

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions