Skip to content

Log levels and removing SLS_DEBUG #1720

Closed

Description

@mthenw

Right now serverless always output current step during deploy. It's always the same, so I'm not sure if it make sense to output that every time.

My proposition is to use log levels and output logs only if user ask for them.

serverless deploy --region us-west-2 --log-level info

Possible log levels:

  • info - same as current default
  • debug - same as current with SLS_DEBUG flag on
  • error - only errors

Proposed solution

(Added in later turn by maintainers)

Ideally if all logging in context of a Framework is pursued through log library which apart of supporting log levels also supports namespaces (debug style) and is already used in tests and some dependencies.

What's important, this will also open the door for pure programmatic use of core without producing CLI logs noise, as proposed log library does not write logs but just emit events, and it's a CLI handler through which a real CLI logs writer (log-node) is initialized which listens for events as emitted by log

When migrating Framework to new logger, ensure to also deprecate --verbose params in all commands, as output should be purely controlled via LOG_LEVEL and LOG_DEBUG environment variables

Activity

  1. eahefnawy commented on Aug 1, 2016

    @eahefnawy
    Contributor

    Yep agreed. I think these prints are just temporary. We'll probably just have a spinner or progress bar. We're also thinking about debugging logs with more info that runs whenever you have SLS_DEBUG (or just DEBUG?) set. But totally agreed, the user should have control over the log level.

  2. mthenw commented on Aug 1, 2016

    @mthenw
    ContributorAuthor

    Yeah, but why env var for that and not CLI param? I guess most of the tools use CLI param for that.

  3. eahefnawy commented on Aug 1, 2016

    @eahefnawy
    Contributor

    env vars has the advantage of always staying in debug mode (as long as you have this env var set) during development... In v0 we had --debug option, which just added the env var for the user. Hmmm maybe we should bring that back.

  4. Bilal-S commented on Aug 2, 2016

    @Bilal-S

    I added a debug view into the system that allows me place the whole framework into node-inspector and do interactive debugging while things are executing. You are able to set breakpoints etc. as well as see the debug output as if the (--debug option) had been selected. You start the system with alternate command: sls-debug. I will post it as a pull request for review.

  5. flomotlik commented on Aug 5, 2016

    @flomotlik
    Contributor

    I like the --log-level idea. At the moment I don't think we should put too much time into it ourselves, but it would be great as a contribution from the community if somebody wants to pick it up.

  6. 15 remaining items

  7. pinned this issue on May 4, 2020
  8. fredericbarthelet commented on May 10, 2020

    @fredericbarthelet
    Contributor

    Following @medikoo recommendations, I updated my PR #7658 in order to use LOG_DEBUG namespace value to output command/hook lifecycle in the terminal for the requested serverless command.

    The way I implemented it is very simple, juste checking for this env var value before writing lifecycle to console.

    All PRs linked to this conversation stalled, and I imagine my simple solution to be too simple for the task at hand here. However, I would be happy to help implementing lifecycle debut print feature following your recommendations, if any :) Any feedback on my PR of what I should develop for this to be integrated ?

  9. medikoo commented on May 11, 2020

    @medikoo
    Contributor

    @fredericbarthelet This PR is about improving how we handle logs in general (by introducing real log levels and namespaces).

    Lifecycle logging could be first one to get advantage of the feature. However first we'd need at least minimal configuration of a new logger.

    Technically just initializing log-node writter in bin/serverless.js will do most of the job. However it'll be good to fine tune the writer, so logs output style resemble one we have now (we should not introduce a dramatic change of how logs look).

    Having that logs for lifecycle engine could be configure just with:

    const log = require('log').get('serverless:lifecycle');
    ...
    log('event %s (%d hooks)', eventName, hooksLength);

    Note that also debug branch, has hardcoded lifecycle logs - it serves as a temporary workaround, until we have them naturally provided with new log engine

  10. fredericbarthelet commented on May 22, 2020

    @fredericbarthelet
    Contributor

    @medikoo, I implemented the feature using log and log-node.
    It works as expected and produces outputs on the terminal based on LOG_DEBUG and LOG_LEVEL env vars. However, as you pointed out, the writer output styles is far from existing Serverless logs style. I did not find any option other than defaultNamespace within the writter to be able to fine tune it.

    While searching for such a way to customize log outputs, I found this neat cli logger called signale which allows output style configuration via JSON out of the box. It misses the automatic use of both previously mentioned env vars, but this could be implemented directly within the logger configuration. WDYT of using such logging library ? Should I stick with log-node writter and make a PR on it as well to allow style configuration options ?

  11. medikoo commented on May 22, 2020

    @medikoo
    Contributor

    However, as you pointed out, the writer output styles is far from existing Serverless logs style. I did not find any option other than defaultNamespace within the writter to be able to fine tune it.

    Yes, I believe we need to prepare our own custom writer (e.g. log-serverless) that derives from log-node and tweaks needed parts. I'll try to prepare one soon, and then we'd be able to jump on it.

    I'll post it here once it's ready

  12. self-assigned this
    on Dec 21, 2020
  13. added this to the v3-ready milestone on Feb 26, 2021
  14. removed this from the v3-ready milestone on Jun 7, 2021
  15. unpinned this issue on Aug 23, 2021
  16. medikoo commented on Dec 6, 2021

    @medikoo
    Contributor

    Closing as that was addressed in context of #9860

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions