File tree Expand file tree Collapse file tree 6 files changed +35
-5
lines changed
Expand file tree Collapse file tree 6 files changed +35
-5
lines changed Original file line number Diff line number Diff line change 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.
77package ginlogger
Original file line number Diff line number Diff 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
1414func LoggingMiddleware (ctx * gin.Context ) {
1515 ctx .Next ()
1616 method := ctx .Request .Method
Original file line number Diff line number Diff line change 66package ginlogger_test
77
88import (
9- "github.com/gin-gonic/gin"
109 "github.com/nextmn/logrus-formatter/ginlogger"
10+
11+ "github.com/gin-gonic/gin"
1112)
1213
1314func ExampleLoggingMiddleware () {
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments