Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bkeepers
Copy link
Contributor

@bkeepers bkeepers commented Nov 9, 2017

cc #320

This PR adds context.log, which will include information about the context in each log message.

module.exports = robot => {
  robot.on('issue_comment.created', context => {
    context.log('Comment created')
  })
}
17:42:05.326Z DEBUG Probot: Comment created
    event: {
      "id": "4cfd3e80-c575-11e7-8e7b-a2d9629ce9eb",
      "event": "issue_comment",
      "action": "created",
      "repository": "robotland/test",
      "installation": 13055
    }

or with LOG_LEVEL=json

{"name":"Probot","hostname":"Brandons-MacBook-Pro-3.local","pid":96993,"event":{"id":"afdcb370-c57d-11e7-9b26-0f31120e45b8","event":"issue_comment","action":"created","repository":"robotland/test","installation":13055},"level":20,"msg":"Comment created","time":"2017-11-09T18:42:07.312Z","v":0}

@bkeepers bkeepers mentioned this pull request Nov 9, 2017
7 tasks
@bkeepers bkeepers changed the title Add context.log to add Add context.log to add event context to each log message Nov 9, 2017
@bkeepers
Copy link
Contributor Author

bkeepers commented Nov 9, 2017

17:42:05.326Z DEBUG Probot: Comment created
    event: {
      "id": "4cfd3e80-c575-11e7-8e7b-a2d9629ce9eb",
      "event": "issue_comment",
      "action": "created",
      "repository": "robotland/test",
      "installation": 13055
    }

I'm not crazy about how verbose every log comment will be because of this.

One idea: update the serializers to include more/less context based on LOG_LEVEL. I'm thinking that LOG_LEVEL=debug would be the trigger that causes serializers to show more context.

@bkeepers bkeepers requested a review from a team November 9, 2017 19:39
@JasonEtco
Copy link
Member

The tough part with logging is that, in production, you only need it when somethings gone wrong and you want to find out why. I've experienced that, and often I look through my webhook deliveries on the GH UI for:

  • Repository
  • Payload ID
  • Event

I think that LOG_LEVEL=debug can be more verbose, but I can see myself getting value from having those three present in a production logger.

@JasonEtco
Copy link
Member

JasonEtco commented Nov 9, 2017

It also doesn't necessarily need to be wrapped in the event: {} object as far as the logs are concerned; to save on precious terminal space it could look like:

17:42:05.326Z DEBUG Probot: Comment created
---
id: 4cfd3e80-c575-11e7-8e7b-a2d9629ce9eb
event: issue_comment.created
repository: robotland/test

With the values in bold (using chalk or something)

* origin/master:
  fix: Move unhandled rejection listener to cli scripts (#339)
  chore: Move index.js into lib/ (#338)
  Add option to develop Probot on Glitch (#306)
  refactor: absorb github-app
  chore: Setup Appveyor (#334)
  docs: Replace examples with include from website (#327)

# Conflicts:
#	lib/index.js
@bkeepers
Copy link
Contributor Author

bkeepers commented Nov 21, 2017

It also doesn't necessarily need to be wrapped in the event: {} object as far as the logs are concerned; to save on precious terminal space it could look like:

We don't currently have a lot of control over this. We're currently using https://github.com/thlorenz/bunyan-format, which we can make improvements to later.

GitHub
bunyan-format - Writable stream that formats bunyan records that are piped into it

@bkeepers bkeepers merged commit c5a0c59 into master Nov 21, 2017
@bkeepers bkeepers deleted the context-log branch November 21, 2017 18:31
bkeepers added a commit that referenced this pull request Nov 24, 2017
* origin/master:
  Fix two 404s to the API docs (#344)
  Add `context.log` to add event context to each log message (#321)
  fix(package): update github to version 12.0.3 (#340)
  chore(packaging): Remove semantic-release from CI (#341)
  refactor: switch ejs for hbs
  fix: Move unhandled rejection listener to cli scripts (#339)
  chore: Move index.js into lib/ (#338)
  Add option to develop Probot on Glitch (#306)
  refactor: absorb github-app
  chore: Setup Appveyor (#334)
  docs: Replace examples with include from website (#327)
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