ronantakizawa/codereview-bench huggingface dataset:
Repository: uber-go/zap
File: http_handler.go (Go)

Code before:
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	"net/http"
)

// A HTTPHandler takes a logger instance and provides methods to enable
// runtime changes to the logger via http.handler interface.
type HTTPHandler struct {
	logger Logger
}

// NewHTTPHandler constructs a new HTTPHandler.
func NewHTTPHandler(logger Logger) *HTTPHandler {
	return &HTTPHandler{logger}
}

// ChangeLogLevel enables changing the logger's log level at runtime.
// It returns an http.Handler that your application can mount to custom routes.
func (h *HTTPHandler) ChangeLogLevel(lvl Level) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		h.logger.SetLevel(lvl)

		var res = "false"
		if h.logger.Enabled(lvl) {
			res = "true"
		}
		w.Write([]byte(res))
	}

	return http.HandlerFunc(fn)
}


Review comment (suggestion):
This is an interesting approach. I'd imagined something more flexible, where `NewHTTPHandler` returns an `http.Handler` directly. That handler accepts GET and PUT requests; GETs return the current logging level, and PUTs accept a form-encoded level.

I'd really like something like this to work:

``` bash
$ curl http://localhost:1234/  # shows the current log level
$ curl --data "level=info" http://localhost:1234/  # sets log level to info & shows log level
```


Code after:
				// received data in wrong format
				http.Error(w, "Bad Request", 400)
				return
			}

			var loggerLevel Level
			err = loggerLevel.UnmarshalText([]byte(p.Level))
			if err != nil {
				// unrecognized level provided by the request
				http.Error(w, "Unrecognized Level", 400)
				return
			}

			logger.SetLevel(loggerLevel)
			currentLevel = loggerLevel.String()
		default:
			http.Error(w, "Method Not Allowed", 405)
			return
		}

		res := payload{currentLevel}
		json.NewEncoder(w).Encode(res)
	}

	return http.HandlerFunc(fn)
}
Repository: uber-go/zap
File: http_handler.go (Go)

Code before:
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	"net/http"
)

// A HTTPHandler takes a logger instance and provides methods to enable
// runtime changes to the logger via http.handler interface.
type HTTPHandler struct {
	logger Logger
}

// NewHTTPHandler constructs a new HTTPHandler.
func NewHTTPHandler(logger Logger) *HTTPHandler {
	return &HTTPHandler{logger}
}

// ChangeLogLevel enables changing the logger's log level at runtime.
// It returns an http.Handler that your application can mount to custom routes.
func (h *HTTPHandler) ChangeLogLevel(lvl Level) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		h.logger.SetLevel(lvl)

		var res = "false"
		if h.logger.Enabled(lvl) {
			res = "true"
		}
		w.Write([]byte(res))
	}

	return http.HandlerFunc(fn)
}


Review comment (suggestion):
Ohh, that sounds good.

So we will be exporting just a function `NewHTTPHandler` returning the `http.Handler`, and it will act according to the HTTP method.
- GET - Retrieve log level
- PUT - Update log level based on the form-encoded data

Thanks for clearing both my doubts. I will implement it soon.


Code after:
				// received data in wrong format
				http.Error(w, "Bad Request", 400)
				return
			}

			var loggerLevel Level
			err = loggerLevel.UnmarshalText([]byte(p.Level))
			if err != nil {
				// unrecognized level provided by the request
				http.Error(w, "Unrecognized Level", 400)
				return
			}

			logger.SetLevel(loggerLevel)
			currentLevel = loggerLevel.String()
		default:
			http.Error(w, "Method Not Allowed", 405)
			return
		}

		res := payload{currentLevel}
		json.NewEncoder(w).Encode(res)
	}

	return http.HandlerFunc(fn)
}
Repository: uber-go/zap
File: http_handler.go (Go)

Code before:
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	"net/http"
)

// A HTTPHandler takes a logger instance and provides methods to enable
// runtime changes to the logger via http.handler interface.
type HTTPHandler struct {
	logger Logger
}

// NewHTTPHandler constructs a new HTTPHandler.
func NewHTTPHandler(logger Logger) *HTTPHandler {
	return &HTTPHandler{logger}
}

// ChangeLogLevel enables changing the logger's log level at runtime.
// It returns an http.Handler that your application can mount to custom routes.
func (h *HTTPHandler) ChangeLogLevel(lvl Level) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		h.logger.SetLevel(lvl)

		var res = "false"
		if h.logger.Enabled(lvl) {
			res = "true"
		}
		w.Write([]byte(res))
	}

	return http.HandlerFunc(fn)
}


Review comment (bug):
If the handler is only going to be used to get/set levels, do we need form-encoded data? Should it just be the level as data? That way to modify the level, it would just be

```
// assume the handler is registered as /debug/loglevel

$ curl -X PUT -d "info" http://localhost:1234/debug/loglevel
```


Code after:
				// received data in wrong format
				http.Error(w, "Bad Request", 400)
				return
			}

			var loggerLevel Level
			err = loggerLevel.UnmarshalText([]byte(p.Level))
			if err != nil {
				// unrecognized level provided by the request
				http.Error(w, "Unrecognized Level", 400)
				return
			}

			logger.SetLevel(loggerLevel)
			currentLevel = loggerLevel.String()
		default:
			http.Error(w, "Method Not Allowed", 405)
			return
		}

		res := payload{currentLevel}
		json.NewEncoder(w).Encode(res)
	}

	return http.HandlerFunc(fn)
}
Repository: uber-go/zap
File: http_handler.go (Go)

Code before:
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	"net/http"
)

// A HTTPHandler takes a logger instance and provides methods to enable
// runtime changes to the logger via http.handler interface.
type HTTPHandler struct {
	logger Logger
}

// NewHTTPHandler constructs a new HTTPHandler.
func NewHTTPHandler(logger Logger) *HTTPHandler {
	return &HTTPHandler{logger}
}

// ChangeLogLevel enables changing the logger's log level at runtime.
// It returns an http.Handler that your application can mount to custom routes.
func (h *HTTPHandler) ChangeLogLevel(lvl Level) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		h.logger.SetLevel(lvl)

		var res = "false"
		if h.logger.Enabled(lvl) {
			res = "true"
		}
		w.Write([]byte(res))
	}

	return http.HandlerFunc(fn)
}


Review comment (bug):
I'd rather get form-encoded data so that (1) we can extend the handler's functionality later if necessary, and (2) we can also support JSON in the same handler (assuming that the caller sets the content type correctly).

Even if we don't want to build fancy debug pages, accepting JSON and form-encoded input will make it much easier for other folks to build nice config pages.


Code after:
				// received data in wrong format
				http.Error(w, "Bad Request", 400)
				return
			}

			var loggerLevel Level
			err = loggerLevel.UnmarshalText([]byte(p.Level))
			if err != nil {
				// unrecognized level provided by the request
				http.Error(w, "Unrecognized Level", 400)
				return
			}

			logger.SetLevel(loggerLevel)
			currentLevel = loggerLevel.String()
		default:
			http.Error(w, "Method Not Allowed", 405)
			return
		}

		res := payload{currentLevel}
		json.NewEncoder(w).Encode(res)
	}

	return http.HandlerFunc(fn)
}
Repository: uber-go/zap
File: http_handler.go (Go)

Code before:
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	"net/http"
)

// A HTTPHandler takes a logger instance and provides methods to enable
// runtime changes to the logger via http.handler interface.
type HTTPHandler struct {
	logger Logger
}

// NewHTTPHandler constructs a new HTTPHandler.
func NewHTTPHandler(logger Logger) *HTTPHandler {
	return &HTTPHandler{logger}
}

// ChangeLogLevel enables changing the logger's log level at runtime.
// It returns an http.Handler that your application can mount to custom routes.
func (h *HTTPHandler) ChangeLogLevel(lvl Level) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		h.logger.SetLevel(lvl)

		var res = "false"
		if h.logger.Enabled(lvl) {
			res = "true"
		}
		w.Write([]byte(res))
	}

	return http.HandlerFunc(fn)
}


Review comment (suggestion):
I think we should be consistent in the `GET` and `PUT` methods.

If we want the ability to extend the handlers in future, then `GET` should also return a key-value list, probably as JSON initially. Ideally, the response from `GET` is a valid input for `PUT`.

Then it makes sense to also support form encoded key-value pairs as input to `PUT` as well (ideally based on content-type).


Code after:
				// received data in wrong format
				http.Error(w, "Bad Request", 400)
				return
			}

			var loggerLevel Level
			err = loggerLevel.UnmarshalText([]byte(p.Level))
			if err != nil {
				// unrecognized level provided by the request
				http.Error(w, "Unrecognized Level", 400)
				return
			}

			logger.SetLevel(loggerLevel)
			currentLevel = loggerLevel.String()
		default:
			http.Error(w, "Method Not Allowed", 405)
			return
		}

		res := payload{currentLevel}
		json.NewEncoder(w).Encode(res)
	}

	return http.HandlerFunc(fn)
}
Repository: uber-go/zap
File: http_handler.go (Go)

Code before:
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	"net/http"
)

// A HTTPHandler takes a logger instance and provides methods to enable
// runtime changes to the logger via http.handler interface.
type HTTPHandler struct {
	logger Logger
}

// NewHTTPHandler constructs a new HTTPHandler.
func NewHTTPHandler(logger Logger) *HTTPHandler {
	return &HTTPHandler{logger}
}

// ChangeLogLevel enables changing the logger's log level at runtime.
// It returns an http.Handler that your application can mount to custom routes.
func (h *HTTPHandler) ChangeLogLevel(lvl Level) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		h.logger.SetLevel(lvl)

		var res = "false"
		if h.logger.Enabled(lvl) {
			res = "true"
		}
		w.Write([]byte(res))
	}

	return http.HandlerFunc(fn)
}


Review comment (bug):
I have implemented it to return JSON string response according to the discussion.

``` sh
# assume that the handler is registered as /debug/loglevel
$ curl http://localhost:3000/debug/loglevel
{"level":"info"}

$ curl -X PUT -d '{"level":"warn"}' http://localhost:3000/debug/loglevel
{"level":"warn"}

$ curl http://localhost:3000/debug/loglevel
{"level":"warn"}
```


Code after:
				// received data in wrong format
				http.Error(w, "Bad Request", 400)
				return
			}

			var loggerLevel Level
			err = loggerLevel.UnmarshalText([]byte(p.Level))
			if err != nil {
				// unrecognized level provided by the request
				http.Error(w, "Unrecognized Level", 400)
				return
			}

			logger.SetLevel(loggerLevel)
			currentLevel = loggerLevel.String()
		default:
			http.Error(w, "Method Not Allowed", 405)
			return
		}

		res := payload{currentLevel}
		json.NewEncoder(w).Encode(res)
	}

	return http.HandlerFunc(fn)
}
Repository: uber-go/zap
File: zbark/debark.go (Go)

Code before:
	zwrap.KeyValueMap
}

func (zbf zapperBarkFields) Fields() map[string]interface{} {
	return zbf.KeyValueMap
}

func zapToBark(zfs []zap.Field) bark.LogFields {
	zbf := zapperBarkFields{make(zwrap.KeyValueMap, len(zfs))}
	for _, zf := range zfs {
		_ = zf.AddTo(zbf)
	}
	return zbf
}

func (z *zapper) Debug(msg string, fields ...zap.Field) {
	z.bl.WithFields(zapToBark(fields)).Debug(msg)
}

func (z *zapper) Info(msg string, fields ...zap.Field) {
	z.bl.WithFields(zapToBark(fields)).Info(msg)
}

func (z *zapper) Warn(msg string, fields ...zap.Field) {
	z.bl.WithFields(zapToBark(fields)).Warn(msg)
}

func (z *zapper) Error(msg string, fields ...zap.Field) {
	z.bl.WithFields(zapToBark(fields)).Error(msg)
}

func (z *zapper) Panic(msg string, fields ...zap.Field) {
	z.bl.WithFields(zapToBark(fields)).Panic(msg)
}

func (z *zapper) Fatal(msg string, fields ...zap.Field) {
	z.bl.WithFields(zapToBark(fields)).Fatal(msg)
}


Review comment (bug):
the `SetLevel` doesn't impact any of these methods. I'd expect that calling `SetLevel(zap.ErrorLevel)` would mean that any `zap.Debug` logs I do would be ignored


Code after:
		}
	}
	return zap.NewCheckedMessage(z, l, msg)
}

func (z *zapper) Debug(msg string, fields ...zap.Field) {
	z.Log(zap.DebugLevel, msg, fields...)
}

func (z *zapper) Info(msg string, fields ...zap.Field) {
	z.Log(zap.InfoLevel, msg, fields...)
}

func (z *zapper) Warn(msg string, fields ...zap.Field) {
	z.Log(zap.WarnLevel, msg, fields...)
}

func (z *zapper) Error(msg string, fields ...zap.Field) {
	z.Log(zap.ErrorLevel, msg, fields...)
}

func (z *zapper) Panic(msg string, fields ...zap.Field) {
	z.Log(zap.PanicLevel, msg, fields...)
}

func (z *zapper) Fatal(msg string, fields ...zap.Field) {
	z.Log(zap.FatalLevel, msg, fields...)
}

func (zbf zapperBarkFields) Fields() map[string]interface{} {
	return zbf
}

func zapToBark(zfs []zap.Field) bark.LogFields {
	zbf := make(zwrap.KeyValueMap, len(zfs))
	for _, zf := range zfs {
		zf.AddTo(zbf)
	}
	return zapperBarkFields(zbf)
}
Repository: uber-go/zap
File: zbark/debark.go (Go)

Code before:
	case zap.PanicLevel:
		bl.Panic(msg)
	case zap.FatalLevel:
		bl.Fatal(msg)
	default:
		panic("passed an unknown zap.Level")
	}
}

func (z *zapper) Level() zap.Level {
	return z.lvl
}

// Change the level of this logger, as well as all its ancestors and
// descendants. This makes it easy to change the log level at runtime
// without restarting your application.
func (z *zapper) SetLevel(l zap.Level) {
	z.lvl = l
}

// Create a child logger, and optionally add some context to that logger.
func (z *zapper) With(fields ...zap.Field) zap.Logger {
	return &zapper{
		lvl: z.lvl,
		bl:  z.bl.WithFields(zapToBark(fields)),
	}
}

func (z *zapper) StubTime() {
	// StubTime stops the logger from including the current time in each
	// message. Instead, it always reports the time as Unix epoch 0. (This is
	// useful in tests and examples.)
	panic("fake implementation")
}

func (z *zapper) Check(l zap.Level, msg string) *zap.CheckedMessage {
	if l < z.lvl {
		return nil
	}
	return zap.NewCheckedMessage(z, l, msg)
}

type zapperBarkFields zwrap.KeyValueMap

func (zbf zapperBarkFields) Fields() map[string]interface{} {
	return zbf
}

func zapToBark(zfs []zap.Field) bark.LogFields {
	zbf := make(zwrap.KeyValueMap, len(zfs))
	for _, zf := range zfs {

Review comment (suggestion):
I'm fine with not checking for now, we don't check in the underlying `jsonLogger` implementation either


Code after:
	case zap.DebugLevel:
		bl.Debug(msg)
	case zap.InfoLevel:
		bl.Info(msg)
	case zap.WarnLevel:
		bl.Warn(msg)
	case zap.ErrorLevel:
		bl.Error(msg)
	case zap.PanicLevel:
		bl.Panic(msg)
	case zap.FatalLevel:
		bl.Fatal(msg)
	default:
		panic(fmt.Errorf("passed an unknown zap.Level: %v", l))
	}
}

func (z *zapper) Level() zap.Level {
	return z.lvl
}

// Change the level of this logger, as well as all its ancestors and
// descendants. This makes it easy to change the log level at runtime
// without restarting your application.
func (z *zapper) SetLevel(l zap.Level) {
	z.lvl = l
}

// Create a child logger, and optionally add some context to that logger.
func (z *zapper) With(fields ...zap.Field) zap.Logger {
	return &zapper{
		lvl: z.lvl,
		bl:  z.bl.WithFields(zapToBark(fields)),
	}
}

func (z *zapper) Check(l zap.Level, msg string) *zap.CheckedMessage {
	switch l {
	case zap.PanicLevel, zap.FatalLevel:
	default:
		if l < z.lvl {
			return nil
		}
	}
	return zap.NewCheckedMessage(z, l, msg)
}

func (z *zapper) Debug(msg string, fields ...zap.Field) {
	z.Log(zap.DebugLevel, msg, fields...)
}
Repository: uber-go/zap
File: zbark/debark_test.go (Go)

Code before:
		if !assert.Equal(t, 0, buf.Len(), "%+v(%d) logged, but shouldn't", f, i) {
			buf.Reset()
		}
	}
	assert.NotPanics(t, func() { logger.Panic("msg") })
}

func TestDebark_Stubs(t *testing.T) {
	logger, _ := newDebark()
	assert.Panics(t, func() { logger.StubTime() })
	assert.NotPanics(t, func() { logger.DFatal("msg") })
}

func TestDebark_zapToBarkFields(t *testing.T) {
	logger, _ := newDebark()
	fields := []zap.Field{
		zap.Bool("a", true),
		zap.Float64("b", float64(0.1)),
		zap.Int("c", 42),
		zap.String("d", "bar"),
		zap.Int64("e", int64(42)),
		zap.Object("f", logger),
		zap.Stringer("g", stringable("g")),
	}
	assert.NotNil(t, logger.With(fields...))

	for _, f := range fields {
		assert.Len(t, zapToBark([]zap.Field{f}).Fields(), 1)
	}
	assert.Len(t, zapToBark(fields).Fields(), len(fields))
}


Review comment (bug):
if you log using `Panic`, shouldn't it cause this test to panic and fail?


Code after:
	logger.SetLevel(zap.PanicLevel)
	for _, l := range levels {
		assert.Nil(t, logger.Check(l, "msg"))
	}

	// We should still panic even if the level isn't enough to log.
	assert.Panics(t, func() {
		logger.SetLevel(zap.FatalLevel)
		logger.Check(zap.PanicLevel, "panic!").Write()
	})
}

func TestDebark_LeveledLogging(t *testing.T) {
	logger, buf := newDebark()
	logger.SetLevel(zap.DebugLevel)
	for _, l := range levels {
		require.Equal(t, 0, buf.Len(), "buffer not zero")
		logger.Log(l, "ohai")
		assert.NotEqual(t, 0, buf.Len(), "%q did not log", l)
		buf.Reset()
	}

	logger.SetLevel(zap.FatalLevel)
	require.Equal(t, 0, buf.Len(), "buffer not zero to begin test")
	for _, l := range append(levels) {
		logger.Log(l, "ohai")
		assert.Equal(t, 0, buf.Len(), "buffer not zero, we should not have logged")
	}

	logger.SetLevel(zap.DebugLevel)
	assert.Panics(t, func() { logger.Log(zap.Level(31337), "") })
	assert.Panics(t, func() { logger.Log(zap.PanicLevel, "") })
}

func TestDebark_Methods(t *testing.T) {
	logger, buf := newDebark()
	logger.SetLevel(zap.DebugLevel)

	funcs := []func(string, ...zap.Field){
		logger.Debug,
		logger.Info,
		logger.Warn,
		logger.Error,
	}

	for i, f := range funcs {
		buf.Reset()
		assert.Equal(t, 0, buf.Len(), "buffer not zero")
		f("ohai")
		assert.NotEqual(t, 0, buf.Len(), "%+v(%d) did not log", f, i)
		buf.Reset()