本文整理汇总了Golang中github.com/Sirupsen/logrus.Entry.WithFields方法的典型用法代码示例。如果您正苦于以下问题:Golang Entry.WithFields方法的具体用法?Golang Entry.WithFields怎么用?Golang Entry.WithFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Sirupsen/logrus.Entry
的用法示例。
在下文中一共展示了Entry.WithFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Judge
/*
Judge run and judge other answers
*/
func Judge(dir, path string, answer []Answer, tests []os.FileInfo, timelimit float64, isConcurrent bool, logger *logrus.Entry) {
logger.WithFields(logrus.Fields{
"state": "check",
"type": "info",
"info": "check answers start"}).Info("Check answers start")
chk, err := chkSetup(dir, path, logger)
if err != nil {
return
}
//file setup
fileSetup(dir, tests, answer, isConcurrent, logger)
//testing
for k, s := range answer { //tests
id := k + 1
name := filepath.Base(s.Name)
outdir := filepath.Join(dir, "temp", fmt.Sprintf("ans_%d", id))
info := ProgInfo{Src: s.Name, Out: filepath.Join(outdir, fmt.Sprintf("ans_%d.out", id))}
test(outdir, name, id, info, tests, timelimit, chk, isConcurrent, logger)
}
logger.WithFields(logrus.Fields{
"state": "check",
"type": "info",
"info": "check answers end"}).Info("Check answers finished")
}
示例2: search
func (k *Kickass) search(s Searcher, log *logrus.Entry) ([]polochon.Torrent, error) {
users := s.users()
result := []polochon.Torrent{}
log = log.WithFields(logrus.Fields{
"search_category": s.category(),
"search_string": s.searchStr(),
})
if err := s.validate(); err != nil {
log.Error(err)
return nil, err
}
for _, u := range users {
torrents, err := k.searchUser(s, log, u)
if err != nil {
return nil, err
}
result = append(result, torrents...)
}
return polochon.FilterTorrents(result), nil
}
示例3: Fire
// Fire fires the event to the ELK beat
func (elk *UDPHook) Fire(e *log.Entry) error {
// Make a copy to safely modify
entry := e.WithFields(nil)
if frameNo := findFrame(); frameNo != -1 {
t := newTrace(frameNo-1, nil)
entry.Data[FileField] = t.String()
entry.Data[FunctionField] = t.Func()
}
data, err := json.Marshal(Frame{
Time: elk.Clock.Now().UTC(),
Type: "trace",
Entry: entry.Data,
Message: entry.Message,
Level: entry.Level.String(),
})
if err != nil {
return Wrap(err)
}
c, err := net.ListenPacket("udp", ":0")
if err != nil {
return Wrap(err)
}
ra, err := net.ResolveUDPAddr("udp", "127.0.0.1:5000")
if err != nil {
return Wrap(err)
}
_, err = (c.(*net.UDPConn)).WriteToUDP(data, ra)
return Wrap(err)
}
示例4: getLogrusLogger
// GetLogrusLogger returns the logrus logger for the context. If one more keys
// are provided, they will be resolved on the context and included in the
// logger. Only use this function if specific logrus functionality is
// required.
func getLogrusLogger(ctx Context, keys ...interface{}) *logrus.Entry {
var logger *logrus.Entry
// Get a logger, if it is present.
loggerInterface := ctx.Value("logger")
if loggerInterface != nil {
if lgr, ok := loggerInterface.(*logrus.Entry); ok {
logger = lgr
}
}
if logger == nil {
// If no logger is found, just return the standard logger.
logger = logrus.NewEntry(logrus.StandardLogger())
}
fields := logrus.Fields{}
for _, key := range keys {
v := ctx.Value(key)
if v != nil {
fields[fmt.Sprint(key)] = v
}
}
return logger.WithFields(fields)
}
示例5: getLogrusLogger
// GetLogrusLogger returns the logrus logger for the context. If one more keys
// are provided, they will be resolved on the context and included in the
// logger. Only use this function if specific logrus functionality is
// required.
func getLogrusLogger(ctx Context, keys ...interface{}) *logrus.Entry {
var logger *logrus.Entry
// Get a logger, if it is present.
loggerInterface := ctx.Value("logger")
if loggerInterface != nil {
if lgr, ok := loggerInterface.(*logrus.Entry); ok {
logger = lgr
}
}
if logger == nil {
fields := logrus.Fields{}
// Fill in the instance id, if we have it.
instanceID := ctx.Value("instance.id")
if instanceID != nil {
fields["instance.id"] = instanceID
}
fields["go.version"] = runtime.Version()
// If no logger is found, just return the standard logger.
logger = logrus.StandardLogger().WithFields(fields)
}
fields := logrus.Fields{}
for _, key := range keys {
v := ctx.Value(key)
if v != nil {
fields[fmt.Sprint(key)] = v
}
}
return logger.WithFields(fields)
}
示例6: DefaultBefore
// DefaultBefore is the default func assigned to *Middleware.Before
func DefaultBefore(entry *logrus.Entry, req *http.Request, remoteAddr string) *logrus.Entry {
return entry.WithFields(logrus.Fields{
"request": req.RequestURI,
"method": req.Method,
"remote": remoteAddr,
})
}
示例7: Format
// Format formats a message from container
func (f *formatter) Format(entry *log.Entry) ([]byte, error) {
e := entry.WithFields(log.Fields{
"container": fmt.Sprintf("%.12s", f.containerID),
})
e.Message = entry.Message
e.Level = f.level
return f.delegate.Format(e)
}
示例8: DefaultAfter
// DefaultAfter is the default func assigned to *Middleware.After
func DefaultAfter(entry *logrus.Entry, res negroni.ResponseWriter, latency time.Duration, name string) *logrus.Entry {
return entry.WithFields(logrus.Fields{
"status": res.Status(),
"text_status": http.StatusText(res.Status()),
"took": latency,
fmt.Sprintf("measure#%s.latency", name): latency.Nanoseconds(),
})
}
示例9: Format
// Format formats a message from container
func (f *formatter) Format(entry *log.Entry) ([]byte, error) {
e := entry.WithFields(log.Fields{
"container": f.container.Name.String(),
})
e.Message = entry.Message
e.Level = f.level
return f.delegate.Format(e)
}
示例10: listMoviesByUser
func (k *Kickass) listMoviesByUser(movies map[string]*polochon.Movie, user string, log *logrus.Entry) error {
query := &kickass.Query{
User: user,
OrderBy: "seeders",
Order: "desc",
Category: string(MoviesCategory),
}
log = log.WithField("explore_user", user)
torrents, err := k.client.ListByUser(query)
if err != nil {
return err
}
for _, t := range torrents {
torrentStr := torrentGuessitStr(t)
guess, err := guessit.Guess(torrentStr)
if err != nil {
continue
}
// Get the torrent quality
torrentQuality := polochon.Quality(guess.Quality)
if !torrentQuality.IsAllowed() {
log.Infof("kickass: unhandled quality: %q", torrentQuality)
continue
}
// Get the movie if its already in the map
m, ok := movies[guess.Title]
if !ok {
// Create a new movie
m = polochon.NewMovie(polochon.MovieConfig{})
m.Title = guess.Title
if guess.Year != 0 {
m.Year = guess.Year
}
}
log.WithFields(logrus.Fields{
"torrent_quality": guess.Quality,
"movie_title": guess.Title,
}).Debug("Adding torrent to the list")
m.Torrents = append(m.Torrents, polochon.Torrent{
Quality: torrentQuality,
URL: t.MagnetURL,
Seeders: t.Seed,
Leechers: t.Leech,
Source: moduleName,
UploadUser: user,
})
movies[m.Title] = m
}
return nil
}
示例11: Open
/*
Open opens file from path
*/
func Open(path string, logger *logrus.Entry) *os.File {
ret, err := os.Open(path)
if err != nil {
logger.WithFields(logrus.Fields{
"type": "error",
"error": err.Error()}).Panic("File Open Failed")
}
return ret
}
示例12: CreateFile
/*
CreateFile creates file from path
*/
func CreateFile(name string, logger *logrus.Entry) *os.File {
ret, err := os.Create(name)
if err != nil {
logger.WithFields(logrus.Fields{
"type": "error",
"error": err.Error()}).Panic("File Creation Failed")
}
return ret
}
示例13: searchUser
func (k *Kickass) searchUser(s Searcher, log *logrus.Entry, user string) ([]polochon.Torrent, error) {
query := &kickass.Query{
User: user,
OrderBy: "seeders",
Order: "desc",
Category: string(s.category()),
Search: s.searchStr(),
}
log = log.WithField("search_user", user)
torrents, err := k.client.Search(query)
if err != nil {
return nil, err
}
result := []polochon.Torrent{}
for _, t := range torrents {
torrentStr := torrentGuessitStr(t)
guess, err := guessit.Guess(torrentStr)
if err != nil {
continue
}
if !s.isValidGuess(guess, log) {
continue
}
// Default quality
if s.category() == ShowsCategory && guess.Quality == "" {
guess.Quality = string(polochon.Quality480p)
}
// Get the torrent quality
torrentQuality := polochon.Quality(guess.Quality)
if !torrentQuality.IsAllowed() {
log.Infof("kickass: unhandled quality: %q", torrentQuality)
continue
}
log.WithFields(logrus.Fields{
"torrent_quality": guess.Quality,
"torrent_name": torrentStr,
}).Debug("Adding torrent to the list")
// Add the torrent
result = append(result, polochon.Torrent{
Quality: torrentQuality,
URL: t.MagnetURL,
Seeders: t.Seed,
Leechers: t.Leech,
Source: moduleName,
UploadUser: user,
})
}
return result, nil
}
示例14: handleConnection
func handleConnection(conn net.Conn, jobd *jobserver.JobServer, cbor *codec.CborHandle, reqLogger *logrus.Logger) {
defer conn.Close()
var reqLog, errLog *logrus.Entry
fields := logrus.Fields{
"remote": conn.RemoteAddr(),
}
errLog = logrus.WithFields(fields)
if reqLogger != nil {
reqLog = reqLogger.WithFields(fields)
}
jobdv := reflect.ValueOf(jobd)
reader := bufio.NewReader(conn)
decoder := codec.NewDecoder(reader, cbor)
writer := bufio.NewWriter(conn)
encoder := codec.NewEncoder(writer, cbor)
for {
var request cborrpc.Request
err := decoder.Decode(&request)
if err == io.EOF {
if reqLog != nil {
reqLog.Debug("Connection closed")
}
return
} else if err != nil {
errLog.WithError(err).Error("Error reading message")
return
}
if reqLog != nil {
reqLog.WithFields(logrus.Fields{
"id": request.ID,
"method": request.Method,
}).Debug("Request")
}
response := doRequest(jobdv, request)
if reqLog != nil {
entry := reqLog.WithField("id", response.ID)
if response.Error != "" {
entry = entry.WithField("error", response.Error)
}
entry.Debug("Response")
}
err = encoder.Encode(response)
if err != nil {
errLog.WithError(err).Error("Error encoding response")
return
}
err = writer.Flush()
if err != nil {
errLog.WithError(err).Error("Error writing response")
return
}
}
}
示例15: ToInfo
/*
ToInfo converts *os.File to os.FileInfo
*/
func ToInfo(file *os.File, logger *logrus.Entry) os.FileInfo {
ret, err := file.Stat()
if err != nil {
logger.WithFields(logrus.Fields{
"type": "error",
"error": IE.String(),
"info": err.Error()}).Panic("Input files not found")
}
return ret
}