Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic logging for python invoke local #4429

Merged
merged 1 commit into from
Dec 3, 2017
Merged

Basic logging for python invoke local #4429

merged 1 commit into from
Dec 3, 2017

Conversation

chernando
Copy link
Contributor

What did you implement:

Closes #4147

This affects both Python 2.7 and Python 3.6 when you try to use logging.

How did you implement it:

Just force logging module to provide a basic config, check logging.basicConfig. Worthy to mention:

This function does nothing if the root logger already has handlers configured for it.

How can we verify it:

YAML:

service: hello

provider:
  name: aws
  runtime: python2.7

functions:
  hello:
    handler: handler.hello

handler.py

from __future__ import print_function
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


def hello(event, context):
    print('hello')
    logger.info('world')

    return '!'

Invoking sls invoke local -f hello, before:

No handlers could be found for logger "handler"

hello
"!"

after:

INFO:handler:world

hello
"!"

With Python 3.6 (changing serverless.yml) it fails silently, before:

hello
"!"

after:

INFO:handler:world

hello
"!"

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@RafalWilinski
Copy link
Contributor

Thanks for submitting this Pull Request @chernando 💯

We'll look into it after 1.24 release. We decided to do a "code freeze" until we release 1.24 so we could test it thoroughly.

@horike37 horike37 added this to the 1.25 milestone Dec 3, 2017
Copy link
Contributor

@horike37 horike37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chernando 👍
Great to see working fine.

LGTM 💯

@horike37 horike37 merged commit b7b3153 into serverless:master Dec 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants