Skip to content

Commit

Permalink
Remove import comments and make examples runnable from pkg.go.dev
Browse files Browse the repository at this point in the history
  • Loading branch information
codemedic committed Aug 19, 2021
1 parent d8d869c commit 831414f
Showing 1 changed file with 16 additions and 64 deletions.
80 changes: 16 additions & 64 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
)

func ExampleNewStderr() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewStderr(
golog.OptionsMust(golog.Options(
golog.WithLevelFromEnv("LOG_LEVEL", golog.Info),
Expand All @@ -24,8 +22,6 @@ func ExampleNewStderr() {
}

func ExampleNewStdout() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewStdout(
golog.OptionsMust(golog.Options(
golog.WithLevelFromEnv("LOG_LEVEL", golog.Info),
Expand All @@ -38,8 +34,6 @@ func ExampleNewStdout() {
}

func ExampleNewLogfile() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewLogfile("/tmp/test-logfile.log", 0644,
golog.OptionsMust(golog.Options(
golog.WithLevelFromEnv("LOG_LEVEL", golog.Info),
Expand All @@ -52,8 +46,6 @@ func ExampleNewLogfile() {
}

func ExampleNewSyslog() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
golog.OptionsMust(golog.Options(
// set the log-level dynamically from the environment
Expand All @@ -68,9 +60,7 @@ func ExampleNewSyslog() {
}

func ExampleWithLevel() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithLevel(golog.Info),
))

Expand All @@ -81,9 +71,7 @@ func ExampleWithLevel() {
}

func ExampleWithPrintLevel() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithPrintLevel(golog.Info),
))

Expand All @@ -93,69 +81,55 @@ func ExampleWithPrintLevel() {
}

func ExampleWithSourceLocationDisabled() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithSourceLocationDisabled(),
))

defer l.Close()
}

func ExampleWithSourceLocationLong() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithSourceLocationLong(),
))

defer l.Close()
}

func ExampleWithSourceLocationShort() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithSourceLocationShort(),
))

defer l.Close()
}

func ExampleWithSourceLocationFromEnv() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(golog.OptionsMust(golog.Options(
l := golog.Must(golog.NewStdout(golog.OptionsMust(golog.Options(
golog.WithSourceLocationFromEnv("LOG_CALLER_LOCATION", "short"),
))))

defer l.Close()
}

func ExampleWithMicrosecondsTimestamp() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithMicrosecondsTimestamp(true),
))

defer l.Close()
}

func ExampleWithMicrosecondsTimestampFromEnv() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(golog.OptionsMust(golog.Options(
l := golog.Must(golog.NewStdout(golog.OptionsMust(golog.Options(
golog.WithMicrosecondsTimestampFromEnv("LOG_MICROSECOND_TIMESTAMP", true),
))))

defer l.Close()
}

func ExampleOptions() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.OptionsMust(
golog.Options(
golog.WithLevelFromEnv("LOG_LEVEL", golog.Info),
Expand All @@ -165,9 +139,7 @@ func ExampleOptions() {
}

func ExampleOptionsMust() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.OptionsMust(
golog.Options(
golog.WithLevelFromEnv("LOG_LEVEL", golog.Info),
Expand All @@ -177,19 +149,15 @@ func ExampleOptionsMust() {
}

func ExampleWithStdlogHandler() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithStdlogHandler(false),
))

defer l.Close()
}

func ExampleWithStdlogSorter() {
// import golog "github.com/codemedic/go-log"

l, _ := golog.NewSyslog(golog.WithStdlogSorter(func(b []byte) golog.Level {
l, _ := golog.NewStdout(golog.WithStdlogSorter(func(b []byte) golog.Level {
switch {
case bytes.HasPrefix(b, []byte("WARNING")):
fallthrough
Expand All @@ -208,8 +176,6 @@ func ExampleWithStdlogSorter() {
}

func ExampleWithSyslogTag() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
golog.WithSyslogTag("my-app-name"),
))
Expand All @@ -218,8 +184,6 @@ func ExampleWithSyslogTag() {
}

func ExampleWithSyslogDaemonURL_uDP() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
golog.WithSyslogDaemonURL("udp://syslog.acme.com:514"),
))
Expand All @@ -228,8 +192,6 @@ func ExampleWithSyslogDaemonURL_uDP() {
}

func ExampleWithSyslogDaemonURL_local() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
golog.WithSyslogDaemonURL("unixgram:///dev/log"),
))
Expand All @@ -238,8 +200,6 @@ func ExampleWithSyslogDaemonURL_local() {
}

func ExampleWithSyslogDaemonURLFromEnv() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(golog.OptionsMust(golog.Options(
golog.WithSyslogDaemonURLFromEnv("LOG_SERVER", "udp://syslog.acme.com:514"),
))))
Expand All @@ -248,39 +208,31 @@ func ExampleWithSyslogDaemonURLFromEnv() {
}

func ExampleWithUTCTimestamp() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.NewStdout(
golog.WithUTCTimestamp(true),
))

defer l.Close()
}

func ExampleWithUTCTimestampFromEnv() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(golog.OptionsMust(golog.Options(
l := golog.Must(golog.NewStdout(golog.OptionsMust(golog.Options(
golog.WithUTCTimestampFromEnv("LOG_UTC", true),
))))

defer l.Close()
}

func ExampleWithWriter() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog(
l := golog.Must(golog.New(
golog.WithWriter(os.Stdout),
))

defer l.Close()
}

func Example() {
// import golog "github.com/codemedic/go-log"

l := golog.Must(golog.NewSyslog())
l := golog.Must(golog.NewStdout())
defer l.Close()

l.Debug("debug message")
Expand Down

0 comments on commit 831414f

Please sign in to comment.