Skip to content

Commit a43b235

Browse files
committed
Improve documentation
1 parent c792013 commit a43b235

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

ginlogger/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// found in the LICENSE file.
44
// SPDX-License-Identifier: MIT
55

6-
// Package ginlogger provide gin gonic middleware to use logrus as logger.
6+
// Package ginlogger provide [github.com/gin-gonic/gin] middleware to use [github.com/sirupsen/logrus] as logger.
77
package ginlogger

ginlogger/ginlogger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
// LoggingMiddleware is a gin gonic middleware to use logrus for logging
13+
// LoggingMiddleware is a [gin.HandlerFunc] to use [logrus] as logger
1414
func LoggingMiddleware(ctx *gin.Context) {
1515
ctx.Next()
1616
method := ctx.Request.Method

ginlogger/ginlogger_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
package ginlogger_test
77

88
import (
9-
"github.com/gin-gonic/gin"
109
"github.com/nextmn/logrus-formatter/ginlogger"
10+
11+
"github.com/gin-gonic/gin"
1112
)
1213

1314
func ExampleLoggingMiddleware() {

logger/doc.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright Louis Royer and the NextMN contributors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style license that can be
3+
// found in the LICENSE file.
4+
// SPDX-License-Identifier: MIT
5+
6+
// Package logger provide a [github.com/sirupsen/logrus] formatter to be used by the [NextMN] project.
7+
//
8+
// [NextMN]: https://github.com/NextMN
9+
package logger

logger/logger.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func newLogFormatter() *logFormatter {
4949
}
5050
}
5151

52-
func Init(prefix string) {
52+
// Init [logrus] with the logger formatter.
53+
func Init(appName string) {
5354
logrus.SetFormatter(newLogFormatter())
54-
logrus.AddHook(newHook(prefix))
55+
logrus.AddHook(newHook(appName))
5556
}

logger/logger_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Louis Royer and the NextMN contributors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style license that can be
3+
// found in the LICENSE file.
4+
// SPDX-License-Identifier: MIT
5+
6+
package logger_test
7+
8+
import (
9+
"github.com/nextmn/logrus-formatter/logger"
10+
11+
"github.com/sirupsen/logrus"
12+
)
13+
14+
func ExampleInit() {
15+
appName := "foo" // name of the application
16+
logger.Init(appName) // init the logrus formatter
17+
// ...
18+
logrus.Info("An event occurred")
19+
}

0 commit comments

Comments
 (0)