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

Log layer design #1

Open
h2non opened this issue Apr 11, 2016 · 4 comments
Open

Log layer design #1

h2non opened this issue Apr 11, 2016 · 4 comments
Assignees

Comments

@h2non
Copy link
Member

h2non commented Apr 11, 2016

My idea is to build a minimalistic logging layer build on top of logrus, having the ability to use a default logger (used by core vinxi package) or alternatively use custom loggers.

In order to make it very simple to use, I think the package should expose a singleton style logger interface, such as (log package consumer side):

import "gopkg.in/vinxi/log.v0"

func main() {
  log.Printf("Write something: %s", "foo")
  log.Debug("Debug message")
  ...
}

From the other side, developers should be able to build and reuse custom loggers with custom formatters and listeners. Possible example:

import "gopkg.in/vinxi/log.v0"

var logConfig := log.NewConfig(...)
var myLog := log.New("myLog", logConfig) // implicitly registered

func main() {
  myLog.Printf("Write something: %s", "foo")
  myLog.Debug("Debug message")
  ...
  // Or you can also retrieve the previously created logger
  log.Logger("myLog").Warm("Got it")
}
@h2non h2non self-assigned this Apr 11, 2016
@h2non
Copy link
Member Author

h2non commented Apr 11, 2016

@groyoh What do you think?

@groyoh
Copy link
Member

groyoh commented Apr 11, 2016

var myLog := log.New("myLog", logConfig)

Would you have to do that for every file or just once the main file?
Also, can you only pass the config for the logger or can you pass a custom logger itself?

@h2non
Copy link
Member Author

h2non commented Apr 11, 2016

If using the generic built-in logger, you won't have to do never, just import tha package.

If using a custom logger, only have to do once time.

@h2non
Copy link
Member Author

h2non commented Apr 12, 2016

Generic logging layer is done. We could consider implementing a logger global store as I described above in order to easily register and fetch logger instances from other packages without the instantiation boilerplate.

My opinion is that we could support that in the future when we actually need it more. Should be trivial to support anyway.

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

2 participants