wongnai / kube-slack

Kubernetes Slack Monitoring
MIT License
323 stars 59 forks source link

Output structured logs with timestamp using bunyan #32

Closed phillipj closed 6 years ago

phillipj commented 6 years ago

Structured logs with timestamp included is incredibly valuable when trying to debug any issues or just want to double check if everything is still running as expected.

bunyan is a proven logger that outputs JSON to stdout.

Example of running this locally:

$ KUBE_USE_KUBECONFIG=true KUBE_USE_CLUSTER=false SLACK_URL=https://example.com node .
{"name":"kube-slack","hostname":"phillipjs-dev-machine","pid":32760,"level":30,"msg":"Kubernetes monitors started","time":"2018-05-04T13:41:08.368Z","v":0}

Lots of ways to alter the bunyan output while running locally or searching through the logs when it runs in the Kubernetes cluster with the bunyan CLI.

Would you consider this useful in this project?

Refs https://github.com/trentm/node-bunyan

whs commented 6 years ago

I thought of adding a proper logging system as well. Thanks!

I think the log should be human readable and not JSON? Or if it is JSON I'd prefer if it is GKE-compatible (I can't find a proper docs on this. It seems to be not documented well) Basically, if you write JSON lines the fluentd in GKE will try to parse them and Stackdriver Logging will show the log lines with correct log level.

phillipj commented 6 years ago

I think the log should be human readable and not JSON?

Yeah, I would agree readable when grepping logs manually, otherwise JSON is better i.e. for sending logs off with fluentd to some log management solution.

bunyan CLI for the rescue to get readable logs:

$ KUBE_USE_KUBECONFIG=true KUBE_USE_CLUSTER=false SLACK_URL=https://example.com node . | bunyan -o short
09:23:53.220Z  INFO kube-slack: Kubernetes monitors started

works just as well with logs directly from kubectl:

$ kubectl logs graphql-f646d6b9d-k8l82 | bunyan -o short
12:42:34.597Z  INFO graphql: GraphQL Server is now running on http://localhost:8080

That CLI's filtering options is also really valuable at times!

Not too opinionated about bunyan or other alternatives though, I just really appreciate a little more structured logs.

whs commented 6 years ago

Now released in latest tag.

Sorry for the long wait, I forgot that this repo has no automated build (as it was moved from whs/kube-slack and Docker Hub not updating the hook)

phillipj commented 6 years ago

Thanks! What's your process for pushing a new version tag, anywhere I can follow to get notified? Wondering so I know when I can bump to the next fixed version.

whs commented 6 years ago

I usually publish when I have a bugfix or a feature.

We just have an intern joined us. He'll work on some of the feature requests, so I estimate that the next release will be by next week.

On Fri, Jun 1, 2018, 5:44 PM Phillip Johnsen notifications@github.com wrote:

Thanks! What's your process for pushing a new version tag, anywhere I can follow to get notified? Wondering so I know when I can bump to the next fixed version.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/wongnai/kube-slack/pull/32#issuecomment-393844010, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVFiyyF7xhTdomWkE1NmHiA2dJGGB7wks5t4RsfgaJpZM4TyrPe .

whs commented 6 years ago

Sorry for the long wait, I've just published v3.4.0 in Docker Hub. :tada:

phillipj commented 6 years ago

Hooooray! Thanks a lot 👍