Skip to content

Commit

Permalink
doc(main): Added documentation (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekkinox authored Jan 24, 2024
1 parent 4fd8471 commit 80535c3
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 8 deletions.
14 changes: 7 additions & 7 deletions docs/applications/showroom.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
## HTTP application demo

This [demo application](https://github.com/ankorstore/yokai-showroom/tree/main/http-demo) is a simple REST API (CRUD) to manage [gophers](https://go.dev/blog/gopher).
This [demo application](https://github.com/ankorstore/yokai-showroom/tree/main/http-demo) is a simple HTTP REST API (CRUD) to manage [gophers](https://go.dev/blog/gopher).

It provides:

- a Yokai application container, with the [fxhttpserver](https://github.com/ankorstore/yokai/tree/main/fxhttpserver) module to offer the REST API
- a Yokai application container, with
- the [fxhttpserver](https://github.com/ankorstore/yokai/tree/main/fxhttpserver) module to expose the REST API
- the [fxorm](https://github.com/ankorstore/yokai/tree/main/fxorm) module to enable database interactions
- a [MySQL](https://www.mysql.com/) container to store the gophers

Available on [:fontawesome-brands-github: GitHub](https://github.com/ankorstore/yokai-showroom/tree/main/http-demo).

## Worker application template
## Worker application demo

This [demo application](https://github.com/ankorstore/yokai-showroom/tree/main/worker-demo) provides is a simple worker example subscribing to [Pub/Sub](https://cloud.google.com/pubsub).

It provides:

- a Yokai application container, with:
- the [fxhttpserver](https://github.com/ankorstore/yokai/tree/main/fxhttpserver) module to offer a Pub/Sub
messages publication endpoint
- the [fxworker](https://github.com/ankorstore/yokai/tree/main/fxworker) module to offer a worker running a Pub/Sub
messages subscriber
- the [fxhttpserver](https://github.com/ankorstore/yokai/tree/main/fxhttpserver) module to expose a Pub/Sub publication endpoint
- the [fxworker](https://github.com/ankorstore/yokai/tree/main/fxworker) module to provide a worker running a Pub/Sub subscriber
- a Pub/Sub emulator container

Available on [:fontawesome-brands-github: GitHub](https://github.com/ankorstore/yokai-showroom/tree/main/worker-demo).
2 changes: 1 addition & 1 deletion docs/modules/fxconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
The [fxconfig](https://github.com/ankorstore/yokai/tree/main/fxconfig) module is automatically loaded by
the [fxcore](https://github.com/ankorstore/yokai/tree/main/fxcore).

You have nothing to install, it's ready to use.
When you use a Yokai [application template](https://ankorstore.github.io/yokai/applications/templates/), you have nothing to install, it's ready to use.

## Documentation

Expand Down
107 changes: 107 additions & 0 deletions docs/modules/fxlog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Log Module

[![ci](https://github.com/ankorstore/yokai/actions/workflows/fxlog-ci.yml/badge.svg)](https://github.com/ankorstore/yokai/actions/workflows/fxlog-ci.yml)
[![go report](https://goreportcard.com/badge/github.com/ankorstore/yokai/fxlog)](https://goreportcard.com/report/github.com/ankorstore/yokai/fxlog)
[![codecov](https://codecov.io/gh/ankorstore/yokai/graph/badge.svg?token=ghUBlFsjhR&flag=fxlog)](https://app.codecov.io/gh/ankorstore/yokai/tree/main/fxlog)
[![Deps](https://img.shields.io/badge/osi-deps-blue)](https://deps.dev/go/github.com%2Fankorstore%2Fyokai%2Ffxlog)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ankorstore/yokai/fxlog)](https://pkg.go.dev/github.com/ankorstore/yokai/fxlog)

## Installation

The [fxlog](https://github.com/ankorstore/yokai/tree/main/fxlog) module is automatically loaded by
the [fxcore](https://github.com/ankorstore/yokai/tree/main/fxcore).

When you use a Yokai [application template](https://ankorstore.github.io/yokai/applications/templates/), you have nothing to install, it's ready to use.

## Documentation

### Configuration

This module provides the possibility to configure:

- the `log level` (possible values: `trace`, `debug`, `info`, `warning`, `error`, `fatal`, `panic`, `no-level` or `disabled`)
- the `log output` (possible values: `noop`, `stdout` or `test`)

Regarding the output:

- `stdout`: to send the log records to `os.Stdout` (default)
- `noop`: to void the log records via `os.Discard`
- `console`: [pretty prints](https://github.com/rs/zerolog#pretty-logging) logs record to `os.Stdout`
- `test`: to send the log records to the [TestLogBuffer](https://github.com/ankorstore/yokai/blob/main/log/logtest/buffer.go) made available in the Fx container, for further assertions

```yaml title="configs/config.yaml"
app:
name: app
env: dev
version: 0.1.0
debug: false
modules:
log:
level: info # by default
output: stdout # by default
```
### Usage
This module makes available the [*log.Logger](https://github.com/ankorstore/yokai/blob/main/log/logger.go) in
Yokai dependency injection system.
It is built on top of [Zerolog](https://github.com/rs/zerolog), see its documentation for more details about available methods.
You can inject it where needed, but it's recommended to use the one carried by the `context.Context` when possible (for automatic logs correlation).

### Testing

This module provides the possibility to easily test your application logs, using the [logtest.TestLogBuffer](https://github.com/ankorstore/yokai/blob/main/log/logtest/buffer.go) with `modules.log.output=test`.

```yaml title="configs/config.test.yaml"
app:
name: test
modules:
log:
output: test # to send logs to test buffer
```

You can use the provided [test assertion helpers](https://github.com/ankorstore/yokai/blob/main/log/logtest/assert.go) in your tests:

- `AssertHasLogRecord`: to assert on exact attributes match
- `AssertHasNotLogRecord`: to assert on exact attributes non match
- `AssertContainLogRecord`: to assert on partial attributes match
- `AssertContainNotLogRecord`: to assert on partial attributes non match

You can then test, for example:

```go title="internal/some_test.go"
package internal_test
import (
"testing"
"github.com/ankorstore/yokai/config"
"github.com/ankorstore/yokai/fxconfig"
"github.com/ankorstore/yokai/fxlog"
"github.com/ankorstore/yokai/log"
"github.com/ankorstore/yokai/log/logtest"
"github.com/foo/bar/internal"
"go.uber.org/fx"
"go.uber.org/fx/fxtest"
)
func TestLogger(t *testing.T) {
var logBuffer logtest.TestLogBuffer
internal.RunTest(
t,
fx.Populate(&logBuffer),
fx.Invoke(func(logger *log.Logger) {
logger.Debug().Msg("test message")
}),
)
// log assertion success
logtest.AssertHasLogRecord(t, buffer, map[string]interface{}{
"level": "debug",
"message": "test message",
})
}
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ nav:
- "Showroom": applications/showroom.md
- "Modules":
- "Config": modules/fxconfig.md
- "Log": modules/fxlog.md

0 comments on commit 80535c3

Please sign in to comment.