httpretty alternatives and similar packages
Based on the "Logging" category.
Alternatively, view httpretty alternatives based on common mentions on social networks and blogs.
-
spew
Implements a deep pretty printer for Go data structures to aid in debugging -
seelog
Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting. -
go-logger
Simple logger for Go programs. Allows custom formats for messages. -
rollingwriter
Rolling writer is an IO util for auto rolling write in go. -
loggo
A logging library for Go. Doesn't use the built in go log standard library, but instead offers a replacement. -
sqldb-logger
A logger for Go SQL database driver without modifying existing *sql.DB stdlib usage. -
ozzo-log
A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets. -
logex
An golang log lib, supports tracking and level, wrap by standard log lib -
gologger
Simple easy to use log lib for go, logs in Colored Cosole, Simple Console, File or Elasticsearch. -
noodlog
🍜 Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content. -
mlog
A simple logging module for go, with a rotating file feature and console logging. -
slf
The Structured Logging Facade (SLF) for Go (like SLF4J but structured and for Go) -
journald
Go implementation of systemd Journal's native API for logging -
Kiwi Logs&Context
Fast, structured, with filters and dynamic sinks. No levels. Logger & context keeper for Go language 🥝 It smell like a mushroom. -
slog
The reference implementation of the Structured Logging Facade (SLF) for Go -
logmatic
Colorized logger for Golang with dynamic log level configuration -
gomol
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs -
kemba
A tiny debug logging tool. Ideal for CLI tools and command applications. Inspired by https://github.com/visionmedia/debug -
go-rethinklogger
Automatically persists all the logs of your Go application inside RethinkDB. -
MrZ's go-logger
:mag: Easy to use, extendable and super fast logging package for Go -
structy/log
A simple to use log system, minimalist but with features for debugging and differentiation of messages
Less time debugging, more time building
Do you think we are missing an alternative of httpretty or a related project?
Popular Comparisons
README
httpretty
Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose
mode, and also on the httputil.DumpRequest and similar functions.
Setting up a logger
You can define a logger with something like
logger := &httpretty.Logger{
Time: true,
TLS: true,
RequestHeader: true,
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
Colors: true, // erase line if you don't like colors
Formatters: []httpretty.Formatter{&httpretty.JSONFormatter{}},
}
This code will set up a logger with sane settings. By default the logger prints nothing but the request line (and the remote address, when using it on the server-side).
Using on the client-side
You can set the transport for the *net/http.Client you are using like this:
client := &http.Client{
Transport: logger.RoundTripper(http.DefaultTransport),
}
// from now on, you can use client.Do, client.Get, etc. to create requests.
If you don't care about setting a new client, you can safely replace your existing http.DefaultClient with this:
http.DefaultClient.Transport = logger.RoundTripper(http.DefaultClient.Transport)
Then httpretty is going to print information about regular requests to your terminal when code such as this is called:
if _, err := http.Get("https://www.google.com/"); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(1)
}
However, have in mind you usually want to use a custom *http.Client to control things such as timeout.
Logging on the server-side
You can use the logger quickly to log requests on your server. For example:
logger.Middleware(mux)
The handler should by a http.Handler. Usually, you want this to be your http.ServeMux
HTTP entrypoint.
For working examples, please see the example directory.
Filtering
You have two ways to filter a request so it isn't printed by the logger.
httpretty.WithHide
You can filter any request by setting a request context before the request reaches httpretty.RoundTripper
:
req = req.WithContext(httpretty.WithHide(ctx))
Filter function
A second option is to implement
type Filter func(req *http.Request) (skip bool, err error)
and set it as the filter for your logger. For example:
logger.SetFilter(func filteredURIs(req *http.Request) (bool, error) {
if req.Method != http.MethodGet {
return true, nil
}
if path := req.URL.Path; path == "/debug" | strings.HasPrefix(path, "/debug/") {
return true, nil
}
return false
})
Formatters
You can define a formatter for any media type by implementing the Formatter interface.
We provide a JSONFormatter for convenience (it is not enabled by default).