github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/ginx/hlog/logrusstore.go (about)

     1  package hlog
     2  
     3  import (
     4  	"github.com/gin-gonic/gin"
     5  	"github.com/sirupsen/logrus"
     6  )
     7  
     8  // LogrusStore stores the log as logurs info.
     9  type LogrusStore struct{}
    10  
    11  // NewLogrusStore returns a new LogrusStore.
    12  func NewLogrusStore() *LogrusStore {
    13  	return &LogrusStore{}
    14  }
    15  
    16  // Store stores the log in database like MySQL, InfluxDB, and etc.
    17  func (s *LogrusStore) Store(c *gin.Context, log *Log) {
    18  	logrus.Infof("http:%+v\n", log)
    19  }
    20  
    21  // Stores is the composite stores.
    22  type Stores struct {
    23  	Composite []Store
    24  }
    25  
    26  // Store stores the log in database like MySQL, InfluxDB, and etc.
    27  func (s *Stores) Store(c *gin.Context, log *Log) {
    28  	for _, v := range s.Composite {
    29  		v.Store(c, log)
    30  	}
    31  }
    32  
    33  // NewStores composes the stores as a Store.
    34  func NewStores(stores ...Store) *Stores {
    35  	return &Stores{Composite: stores}
    36  }