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

support --log / -l for invoke local (especially for Python logging) #4147

Closed
ceefour opened this issue Aug 23, 2017 · 5 comments
Closed

support --log / -l for invoke local (especially for Python logging) #4147

ceefour opened this issue Aug 23, 2017 · 5 comments

Comments

@ceefour
Copy link

ceefour commented Aug 23, 2017

Feature Proposal

Description

Currently Python logging doesn't output anything using invoke local

Add logging support similar to invoke -l

Especially with Python logging

I'd argue that --log for invoke local should be enabled by default, rather than needing to be enabled explicitly.

Additional Data

  • Serverless Framework Version you're using: 1.20.2
  • Operating System: Windows 10
@dschep
Copy link
Contributor

dschep commented Aug 31, 2017

I don't quite follow what you're asking for. sls invoke local already shows stderr and stdout, unlike sls invoke so there's no need to add a --log option AFAICT.

Here's the aws-python3 template with print('foo') added:

$ sls invoke local -f hello
foo
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
$ sls invoke -f hello
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
$ sls invoke -l -f hello
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
--------------------------------------------------------------------
START RequestId: 1e2d9cd9-8e90-11e7-bf98-a994067d9d91 Version: $LATEST
foo
END RequestId: 1e2d9cd9-8e90-11e7-bf98-a994067d9d91
REPORT RequestId: 1e2d9cd9-8e90-11e7-bf98-a994067d9d91  Duration: 0.39 ms       Billed Duration: 100 ms    Memory
 Size: 1024 MB    Max Memory Used: 21 MB

and using the python logging module:

[:wat] $ sls invoke local -f hello
ERROR:root:foo

{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
$ sls invoke -f hello
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
$ sls invoke -l -f hello
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
--------------------------------------------------------------------
START RequestId: aa1afece-8e90-11e7-a0a7-fbe2e186fe49 Version: $LATEST
2017-08-31 17:09:23.822 (-04:00)        aa1afece-8e90-11e7-a0a7-fbe2e186fe49    [ERROR] foo
END RequestId: aa1afece-8e90-11e7-a0a7-fbe2e186fe49
REPORT RequestId: aa1afece-8e90-11e7-a0a7-fbe2e186fe49  Duration: 1.02 ms       Billed Duration: 100 ms    
emory Size: 1024 MB     Max Memory Used: 21 MB

@ceefour
Copy link
Author

ceefour commented Aug 31, 2017

@dschep mine behavior is different:

def search(event, context):
    logger = logging.getLogger('posts')
    logger.setLevel(logging.DEBUG)
    logger.info('log INFO event: %s', event)
    logger.error('log ERROR event: %s', event)
    print('print event: %s' % event)

Result:

C:\Users\ceefour\git\modelooks\serverless>sls invoke local -s local -f postsSearch
log ERROR event: {}

print event: {}

@dschep
Copy link
Contributor

dschep commented Aug 31, 2017

@ceefour, that's odd. I'm not sure why it'd be doing that 😕

@ceefour
Copy link
Author

ceefour commented Aug 31, 2017

@dschep there is light:

def search(event, context):
    logger = logging.getLogger('posts')
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    logger.addHandler(ch)
    logger.info('log INFO event: %s', event)
    logger.error('log ERROR event: %s', event)
    print('print event: %s' % event)

gives:

C:\Users\ceefour\git\modelooks\serverless>sls invoke local -s local -f postsSearch
log INFO event: {}

log ERROR event: {}

print event: {}

which is kinda acceptable if I'm so inclined. But I don't get why I have to do so much boilerplate while you (and AWS) can get sane nice defaults ?

Perhaps this is not so much request for -l but rather better support for ... Python on Windows (?) maybe.

@dschep
Copy link
Contributor

dschep commented Aug 31, 2017

Hmm. I'm guessing AWS does something in their python code before it imports and calls your handler, invoke.py could probably do the same/similar if someone knows what setup AWS is doing.

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

No branches or pull requests

3 participants