Skip to content

Commit

Permalink
docs: autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Sep 7, 2023
1 parent 1e9c7a2 commit a455667
Showing 1 changed file with 120 additions and 52 deletions.
172 changes: 120 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<h1 align="center">AtomicGo | template</h1>
<h1 align="center">AtomicGo | splitslog</h1>

<p align="center">
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Ftemplate&style=flat-square" alt="Downloads">
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fatomicgo.dev%2Fapi%2Fshields%2Fsplitslog&style=flat-square" alt="Downloads">

<a href="https://github.com/atomicgo/template/releases">
<img src="https://img.shields.io/github/v/release/atomicgo/template?style=flat-square" alt="Latest Release">
<a href="https://github.com/atomicgo/splitslog/releases">
<img src="https://img.shields.io/github/v/release/atomicgo/splitslog?style=flat-square" alt="Latest Release">
</a>

<a href="https://codecov.io/gh/atomicgo/template" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/atomicgo/template/go.yml?style=flat-square" alt="Tests">
<a href="https://codecov.io/gh/atomicgo/splitslog" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/atomicgo/splitslog/go.yml?style=flat-square" alt="Tests">
</a>

<a href="https://codecov.io/gh/atomicgo/template" target="_blank">
<img src="https://img.shields.io/codecov/c/gh/atomicgo/template?color=magenta&logo=codecov&style=flat-square" alt="Coverage">
<a href="https://codecov.io/gh/atomicgo/splitslog" target="_blank">
<img src="https://img.shields.io/codecov/c/gh/atomicgo/splitslog?color=magenta&logo=codecov&style=flat-square" alt="Coverage">
</a>

<a href="https://codecov.io/gh/atomicgo/template">
<!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-3-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end -->
<a href="https://codecov.io/gh/atomicgo/splitslog">
<!-- unittestcount:start --><img src="https://img.shields.io/badge/Unit_Tests-1-magenta?style=flat-square" alt="Unit test count"><!-- unittestcount:end -->
</a>

<a href="https://opensource.org/licenses/MIT" target="_blank">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square" alt="License: MIT">
</a>

<a href="https://goreportcard.com/report/github.com/atomicgo/template" target="_blank">
<img src="https://goreportcard.com/badge/github.com/atomicgo/template?style=flat-square" alt="Go report">
<a href="https://goreportcard.com/report/github.com/atomicgo/splitslog" target="_blank">
<img src="https://goreportcard.com/badge/github.com/atomicgo/splitslog?style=flat-square" alt="Go report">
</a>

</p>

---

<p align="center">
<strong><a href="https://pkg.go.dev/atomicgo.dev/template#section-documentation" target="_blank">Documentation</a></strong>
<strong><a href="https://pkg.go.dev/atomicgo.dev/splitslog#section-documentation" target="_blank">Documentation</a></strong>
|
<strong><a href="https://github.com/atomicgo/atomicgo/blob/main/CONTRIBUTING.md" target="_blank">Contributing</a></strong>
|
Expand All @@ -51,7 +51,7 @@
</tbody>
</table>
</p>
<h3 align="center"><pre>go get atomicgo.dev/template</pre></h3>
<h3 align="center"><pre>go get atomicgo.dev/splitslog</pre></h3>
<p align="center">
<table>
<tbody>
Expand All @@ -63,19 +63,72 @@

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# template
# splitslog

```go
import "atomicgo.dev/template"
import "atomicgo.dev/splitslog"
```

Package template is used to generate new AtomicGo repositories.
Package splitslog provides a handler that splits log records to different handlers based on their level.

Write the description of the module here. You can use \*\*markdown\*\*\! This description should clearly explain what the package does.
The most common use case is to split logs to stdout and stderr based on their level.

Example description: https://golang.org/src/encoding/gob/doc.go
```
func main() {
splitter := splitslog.Splitter{
// Debug and info messages are printed to stdout.
slog.LevelDebug: slog.NewJSONHandler(os.Stdout, nil),
slog.LevelInfo: slog.NewJSONHandler(os.Stdout, nil),
// Warn and error messages are printed to stderr.
slog.LevelWarn: slog.NewJSONHandler(os.Stderr, nil),
slog.LevelError: slog.NewJSONHandler(os.Stderr, nil),
}
handler := splitslog.NewSplitHandler(splitter)
logger := slog.New(handler)
logger.Info("info message prints to stdout")
logger.Error("error message prints to stderr")
// Output:
// stdout: {"time":"2023-09-07T16:56:22.563817+02:00","level":"INFO","msg":"info message prints to stdout"}
// stderr: {"time":"2023-09-07T16:56:22.564103+02:00","level":"ERROR","msg":"error message prints to stderr"}
}
```

## Index

- [type SplitHandler](<#SplitHandler>)
- [func NewSplitHandler\(splitter Splitter\) \*SplitHandler](<#NewSplitHandler>)
- [func \(h \*SplitHandler\) Enabled\(ctx context.Context, level slog.Level\) bool](<#SplitHandler.Enabled>)
- [func \(h \*SplitHandler\) Handle\(ctx context.Context, r slog.Record\) error](<#SplitHandler.Handle>)
- [func \(h \*SplitHandler\) WithAttrs\(attrs \[\]slog.Attr\) slog.Handler](<#SplitHandler.WithAttrs>)
- [func \(h \*SplitHandler\) WithGroup\(name string\) slog.Handler](<#SplitHandler.WithGroup>)
- [type Splitter](<#Splitter>)


<a name="SplitHandler"></a>
## type [SplitHandler](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L14-L18>)

SplitHandler is a handler that splits log records to different handlers based on their level.

```go
type SplitHandler struct {
Splitter Splitter
// contains filtered or unexported fields
}
```

<details><summary>Example (Demo)</summary>
<a name="NewSplitHandler"></a>
### func [NewSplitHandler](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L21>)

```go
func NewSplitHandler(splitter Splitter) *SplitHandler
```

NewSplitHandler returns a new SplitHandler.

<details><summary>Example</summary>
<p>


Expand All @@ -84,64 +137,79 @@ Example description: https://golang.org/src/encoding/gob/doc.go
package main

import (
"atomicgo.dev/template"
"fmt"
"atomicgo.dev/splitslog"
"log/slog"
"os"
)

func main() {
fmt.Println(template.HelloWorld())
splitter := splitslog.Splitter{
// Debug and info messages are printed to stdout.
slog.LevelDebug: slog.NewJSONHandler(os.Stdout, nil),
slog.LevelInfo: slog.NewJSONHandler(os.Stdout, nil),
// Warn and error messages are printed to stderr.
slog.LevelWarn: slog.NewJSONHandler(os.Stderr, nil),
slog.LevelError: slog.NewJSONHandler(os.Stderr, nil),
}

handler := splitslog.NewSplitHandler(splitter)
logger := slog.New(handler)

logger.Info("info message prints to stdout")
logger.Error("error message prints to stderr")

// stdout: {"time":"2023-09-07T16:56:22.563817+02:00","level":"INFO","msg":"info message prints to stdout"}
// stderr: {"time":"2023-09-07T16:56:22.564103+02:00","level":"ERROR","msg":"error message prints to stderr"}
}
```

#### Output

```
Hello, World!
```

</p>
</details>

## Index
<a name="SplitHandler.Enabled"></a>
### func \(\*SplitHandler\) [Enabled](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L39>)

- [func HelloWorld\(\) string](<#HelloWorld>)
```go
func (h *SplitHandler) Enabled(ctx context.Context, level slog.Level) bool
```

Enabled implements Handler.Enabled.

<a name="HelloWorld"></a>
## func [HelloWorld](<https://github.com/atomicgo/splitslog/blob/main/template.go#L4>)
<a name="SplitHandler.Handle"></a>
### func \(\*SplitHandler\) [Handle](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L44>)

```go
func HelloWorld() string
func (h *SplitHandler) Handle(ctx context.Context, r slog.Record) error
```

HelloWorld returns \`Hello, World\!\`.
Handle implements Handler.Handle.

<details><summary>Example</summary>
<p>
<a name="SplitHandler.WithAttrs"></a>
### func \(\*SplitHandler\) [WithAttrs](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L61>)

```go
func (h *SplitHandler) WithAttrs(attrs []slog.Attr) slog.Handler
```

WithAttrs implements Handler.WithAttrs.

<a name="SplitHandler.WithGroup"></a>
### func \(\*SplitHandler\) [WithGroup](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L70>)

```go
package main
func (h *SplitHandler) WithGroup(name string) slog.Handler
```

import (
"atomicgo.dev/template"
"fmt"
)
WithGroup implements Handler.WithGroup.

func main() {
fmt.Println(template.HelloWorld())
}
```
<a name="Splitter"></a>
## type [Splitter](<https://github.com/atomicgo/splitslog/blob/main/splitslog.go#L11>)

#### Output
Splitter is a map of log levels to handlers. The default log levels \(slog.LevelDebug, slog.LevelInfo, slog.LevelWarn, slog.LevelError\) must be present, otherwise the SplitHandler panics.

```go
type Splitter map[slog.Level]slog.Handler
```
Hello, World!
```

</p>
</details>

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)

Expand Down

0 comments on commit a455667

Please sign in to comment.