Code Monkey home page Code Monkey logo

honeylogger's Introduction

Version GolangCI Lint Golang Tests

Honeylogger

Simple logger with DataDog’s span support. Uses Zap under the hood.


Installation

Now you can add this package via;

go get github.com/deliveryhero/honeylogger

GolangCI Linter Settings

You can add these lines to your existing linter yaml if you use wrapcheck linter:

linters-settings:
  wrapcheck:
    ignoreSigs:
      - .Errorf(
      - errors.New(
      - errors.Unwrap(
      - .Wrap(
      - .Wrapf(
      - .WithMessage(
      - .WithMessagef(
      - .WithStack(
      - .WrapError(

Usage

logger := logging.NewLogger("stderr")
logger.Fatal(errors.Wrap(err, "invalid server port"))

With context

This adds span information if context has DataDog Span object.

logger := logging.NewLogger("stderr")
span, spanCtx := tracer.StartSpanFromContext(...)
defer func() {
	span.Finish(tracer.WithError(err))
}()
    
logger.InfoContext(spanCtx, fmt.Sprintf("[outboxService.ticked] non published count: %v", count))

Direct use with DataDog Span

logger := logging.NewLogger("stderr")
   
span, spanCtx := tracer.StartSpanFromContext(...)
defer func() {
	span.Finish(tracer.WithError(err))
}()
    
logger.InfoSpan( fmt.Sprintf("[outboxService.ticked] non published count: %v",count), span)

Rake Tasks

rake -T

rake bump[revision]     # bump version, default is: patch
rake default            # default task
rake doc[port]          # run doc server
rake mockery            # run mockery
rake publish[revision]  # publish new version of the library, default is: patch
rake test               # run tests

Tests

To run tests, use rake test or;

go test -p 1 -v -race ./...

Mock Usage

logger := &mocks.Logger{}
logger.On("Info", mock.Anything).Return()
logger.On("InfoSpan", mock.Anything, mock.Anything, mock.Anything).Return()
logger.On("InfoContext", mock.Anything, mock.Anything, mock.Anything).Return()

Godoc Server

Make sure you have already installed godoc unless:

go install golang.org/x/tools/cmd/godoc@latest
godoc -http=:9009

or, use rake tasks:

  • rake doc uses default port which is 9009
  • rake doc[8008] uses given 8008 as port number

then;

# for default port
open http://localhost:9009/pkg/github.com/deliveryhero/honeylogger/logging/

Publishing New Release

Prerequisites

  • You need to be in main branch
  • You need to be ready to bump to a new version

Use rake publish[revision] task to bump new version and push newly created tag and updated code to remote and verify go package. (all in one!)

  • rake publish: 0.0.0 -> 0.0.1, default revision is patch
  • rake publish[minor]: 0.0.0 -> 0.1.0
  • rake publish[major]: 0.0.0 -> 1.0.0

Contributor(s)


Contribute

All PR’s are welcome!

  1. fork (https://github.com/deliveryhero/honeylogger/fork)
  2. Create your branch (git checkout -b my-feature)
  3. commit yours (git commit -am 'add some functionality')
  4. push your branch (git push origin my-feature)
  5. Than create a new Pull Request!

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

honeylogger's People

Contributors

erhanakp avatar hakankutluay avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.