This commit is contained in:
a 2022-11-03 10:18:09 -05:00
parent 64792032f4
commit 99eea905a5
20 changed files with 56 additions and 56 deletions

View File

@ -7,7 +7,7 @@ opinionated defaults on zerolog
# Zero Allocation JSON Logger # Zero Allocation JSON Logger
[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/git.tuxpa.in/a/zlog) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/zlog/master/LICENSE) [![Build Status](https://travis-ci.org/rs/zlog.svg?branch=master)](https://travis-ci.org/rs/zlog) [![Coverage](http://gocover.io/_badge/git.tuxpa.in/a/zlog)](http://gocover.io/git.tuxpa.in/a/zlog) [![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/tuxpa.in/a/zlog) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/zlog/master/LICENSE) [![Build Status](https://travis-ci.org/rs/zlog.svg?branch=master)](https://travis-ci.org/rs/zlog) [![Coverage](http://gocover.io/_badge/tuxpa.in/a/zlog)](http://gocover.io/tuxpa.in/a/zlog)
The zlog package provides a fast and simple logger dedicated to JSON output. The zlog package provides a fast and simple logger dedicated to JSON output.
@ -21,7 +21,7 @@ To keep the code base and the API simple, zlog focuses on efficient structured l
## Who uses zlog ## Who uses zlog
Find out [who uses zlog](https://git.tuxpa.in/a/zlog/wiki/Who-uses-zlog) and add your company / project to the list. Find out [who uses zlog](https://tuxpa.in/a/zlog/wiki/Who-uses-zlog) and add your company / project to the list.
## Features ## Features
@ -40,21 +40,21 @@ Find out [who uses zlog](https://git.tuxpa.in/a/zlog/wiki/Who-uses-zlog) and add
## Installation ## Installation
```bash ```bash
go get -u git.tuxpa.in/a/zlog/log go get -u tuxpa.in/a/zlog/log
``` ```
## Getting Started ## Getting Started
### Simple Logging Example ### Simple Logging Example
For simple logging, import the global logger package **git.tuxpa.in/a/zlog/log** For simple logging, import the global logger package **tuxpa.in/a/zlog/log**
```go ```go
package main package main
import ( import (
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -77,8 +77,8 @@ func main() {
package main package main
import ( import (
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -108,8 +108,8 @@ func main() {
package main package main
import ( import (
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -145,8 +145,8 @@ package main
import ( import (
"flag" "flag"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -196,8 +196,8 @@ You may choose to log without a specific level by using the `Log` method. You ma
package main package main
import ( import (
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -221,8 +221,8 @@ package main
import ( import (
"errors" "errors"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -246,10 +246,10 @@ package main
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
"git.tuxpa.in/a/zlog/pkgerrors" "tuxpa.in/a/zlog/pkgerrors"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -293,8 +293,8 @@ package main
import ( import (
"errors" "errors"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
func main() { func main() {
@ -520,7 +520,7 @@ stdlog.Print("hello world")
### Integration with `net/http` ### Integration with `net/http`
The `git.tuxpa.in/a/zlog/hlog` package provides some helpers to integrate zlog with `http.Handler`. The `tuxpa.in/a/zlog/hlog` package provides some helpers to integrate zlog with `http.Handler`.
In this example we use [alice](https://github.com/justinas/alice) to install logger for better readability. In this example we use [alice](https://github.com/justinas/alice) to install logger for better readability.

View File

@ -1,4 +1,4 @@
module git.tuxpa.in/a/zlog/cmd/lint module tuxpa.in/a/zlog/cmd/lint
go 1.15 go 1.15

View File

@ -30,7 +30,7 @@ func init() {
flag.Parse() flag.Parse()
// add zlog to recursively ignored packages // add zlog to recursively ignored packages
recursivelyIgnoredPkgs = append(recursivelyIgnoredPkgs, "git.tuxpa.in/a/zlog") recursivelyIgnoredPkgs = append(recursivelyIgnoredPkgs, "tuxpa.in/a/zlog")
args := flag.Args() args := flag.Args()
if len(args) != 1 { if len(args) != 1 {
fmt.Fprintln(os.Stderr, "you must provide exactly one package path") fmt.Fprintln(os.Stderr, "you must provide exactly one package path")
@ -49,14 +49,14 @@ func main() {
os.Exit(1) os.Exit(1)
} }
// get the git.tuxpa.in/a/zlog.Event type // get the tuxpa.in/a/zlog.Event type
event := getEvent(p) event := getEvent(p)
if event == nil { if event == nil {
fmt.Fprintln(os.Stderr, "Error: git.tuxpa.in/a/zlog.Event declaration not found, maybe zlog is not imported in the scanned package?") fmt.Fprintln(os.Stderr, "Error: tuxpa.in/a/zlog.Event declaration not found, maybe zlog is not imported in the scanned package?")
os.Exit(1) os.Exit(1)
} }
// get all selections (function calls) with the git.tuxpa.in/a/zlog.Event (or pointer) receiver // get all selections (function calls) with the tuxpa.in/a/zlog.Event (or pointer) receiver
selections := getSelectionsWithReceiverType(p, event) selections := getSelectionsWithReceiverType(p, event)
// print the violations (if any) // print the violations (if any)
@ -80,7 +80,7 @@ func main() {
func getEvent(p *loader.Program) types.Type { func getEvent(p *loader.Program) types.Type {
for _, pkg := range p.AllPackages { for _, pkg := range p.AllPackages {
if strings.HasSuffix(pkg.Pkg.Path(), "git.tuxpa.in/a/zlog") { if strings.HasSuffix(pkg.Pkg.Path(), "tuxpa.in/a/zlog") {
for _, d := range pkg.Defs { for _, d := range pkg.Defs {
if d != nil && d.Name() == "Event" { if d != nil && d.Name() == "Event" {
return d.Type() return d.Type()

View File

@ -9,7 +9,7 @@ import (
"testing" "testing"
"time" "time"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
) )
func ExampleConsoleWriter() { func ExampleConsoleWriter() {

View File

@ -8,7 +8,7 @@ import (
"sync" "sync"
"time" "time"
"git.tuxpa.in/a/zlog/diode/internal/diodes" "tuxpa.in/a/zlog/diode/internal/diodes"
) )
var bufPool = &sync.Pool{ var bufPool = &sync.Pool{

View File

@ -6,8 +6,8 @@ import (
"fmt" "fmt"
"os" "os"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/diode" "tuxpa.in/a/zlog/diode"
) )
func ExampleNewWriter() { func ExampleNewWriter() {

View File

@ -9,9 +9,9 @@ import (
"testing" "testing"
"time" "time"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/diode" "tuxpa.in/a/zlog/diode"
"git.tuxpa.in/a/zlog/internal/cbor" "tuxpa.in/a/zlog/internal/cbor"
) )
func TestNewWriter(t *testing.T) { func TestNewWriter(t *testing.T) {

View File

@ -5,7 +5,7 @@ package zlog
// This file contains bindings to do binary encoding. // This file contains bindings to do binary encoding.
import ( import (
"git.tuxpa.in/a/zlog/internal/cbor" "tuxpa.in/a/zlog/internal/cbor"
) )
var ( var (

View File

@ -6,7 +6,7 @@ package zlog
// JSON encoded byte stream. // JSON encoded byte stream.
import ( import (
"git.tuxpa.in/a/zlog/internal/json" "tuxpa.in/a/zlog/internal/json"
) )
var ( var (

View File

@ -7,9 +7,9 @@ import (
"time" "time"
"github.com/rs/xid" "github.com/rs/xid"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/hlog/internal/mutil" "tuxpa.in/a/zlog/hlog/internal/mutil"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
// FromRequest gets the logger in the request's context. // FromRequest gets the logger in the request's context.

View File

@ -9,8 +9,8 @@ import (
"net/http/httptest" "net/http/httptest"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/hlog" "tuxpa.in/a/zlog/hlog"
) )
// fake alice to avoid dep // fake alice to avoid dep

View File

@ -14,8 +14,8 @@ import (
"testing" "testing"
"github.com/rs/xid" "github.com/rs/xid"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/internal/cbor" "tuxpa.in/a/zlog/internal/cbor"
) )
func decodeIfBinary(out *bytes.Buffer) string { func decodeIfBinary(out *bytes.Buffer) string {

View File

@ -8,7 +8,7 @@ import (
"os" "os"
"time" "time"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
) )
func writeLog(fname string, count int, useCompress bool) { func writeLog(fname string, count int, useCompress bool) {

View File

@ -25,8 +25,8 @@ import (
"strings" "strings"
"github.com/coreos/go-systemd/v22/journal" "github.com/coreos/go-systemd/v22/journal"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/internal/cbor" "tuxpa.in/a/zlog/internal/cbor"
) )
const defaultJournalDPrio = journal.PriNotice const defaultJournalDPrio = journal.PriNotice

View File

@ -7,8 +7,8 @@ import (
"io" "io"
"testing" "testing"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/journald" "tuxpa.in/a/zlog/journald"
) )
func ExampleNewJournalDWriter() { func ExampleNewJournalDWriter() {

4
log.go
View File

@ -2,12 +2,12 @@
// //
// A global Logger can be use for simple logging: // A global Logger can be use for simple logging:
// //
// import "git.tuxpa.in/a/zlog/log" // import "tuxpa.in/a/zlog/log"
// //
// log.Info().Msg("hello world") // log.Info().Msg("hello world")
// // Output: {"time":1494567715,"level":"info","message":"hello world"} // // Output: {"time":1494567715,"level":"info","message":"hello world"}
// //
// NOTE: To import the global logger, import the "log" subpackage "git.tuxpa.in/a/zlog/log". // NOTE: To import the global logger, import the "log" subpackage "tuxpa.in/a/zlog/log".
// //
// Fields can be added to log messages: // Fields can be added to log messages:
// //

View File

@ -8,7 +8,7 @@ import (
"os" "os"
"time" "time"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
) )
// Logger is the global logger. // Logger is the global logger.

View File

@ -9,8 +9,8 @@ import (
"os" "os"
"time" "time"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
"git.tuxpa.in/a/zlog/log" "tuxpa.in/a/zlog/log"
) )
// setup would normally be an init() function, however, there seems // setup would normally be an init() function, however, there seems

View File

@ -10,7 +10,7 @@ import (
"os" "os"
"time" "time"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
) )
func ExampleNew() { func ExampleNew() {

View File

@ -8,7 +8,7 @@ import (
"testing" "testing"
"github.com/pkg/errors" "github.com/pkg/errors"
"git.tuxpa.in/a/zlog" "tuxpa.in/a/zlog"
) )
func TestLogStack(t *testing.T) { func TestLogStack(t *testing.T) {