本文整理汇总了Golang中github.com/Sirupsen/logrus.Entry.WithField方法的典型用法代码示例。如果您正苦于以下问题:Golang Entry.WithField方法的具体用法?Golang Entry.WithField怎么用?Golang Entry.WithField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Sirupsen/logrus.Entry
的用法示例。
在下文中一共展示了Entry.WithField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: subAppStart
// Start statrs a sub app in its own goroutine
func (a *App) subAppStart(app subapp.App, log *logrus.Entry) {
log.Debugf("starting sub app %q", app.Name())
a.wg.Add(1)
go func() {
defer a.wg.Done()
if err := app.Run(log); err != nil {
// Check the error type, if it comes from a panic recovery
// reload the app
switch e := err.(type) {
case *errors.Error:
errors.LogErrors(log.WithField("app", app.Name()), e)
// Notify the safeguard of the error
a.safeguard.Event()
// Write to the reload channel in a goroutine to prevent deadlocks
go func() {
a.reload <- app
}()
// Only log the error
default:
log.Error(err)
go a.Stop(log)
}
}
}()
log.Debugf("sub app %q started", app.Name())
}
示例2: Stop
// Stop stops the app
func (b *Base) Stop(log *logrus.Entry) {
log.WithField("app", b.AppName).Debug("stopping app asynchronously")
if b.AppStatus == Started {
close(b.Done)
b.AppStatus = Stopped
}
}
示例3: cleanDoneVideos
func (c *Cleaner) cleanDoneVideos(log *logrus.Entry) {
list, err := c.config.Downloader.Client.List()
if err != nil {
log.Errorf("error while getting torrent list: %q", err)
return
}
for _, t := range list {
torrentInfos := t.Infos()
log = log.WithField("torrent_name", torrentInfos.Name)
// Check if the file is ready to be cleaned
isReady := c.isReadyToBeCleaned(t, log)
if !isReady {
log.Debug("torrent is not ready to be cleaned")
continue
}
// We remove the torrent
log.Debugf("removing torrent")
err := c.config.Downloader.Client.Remove(t)
if err != nil {
log.Errorf("got error when removing torrent : %q", err)
continue
}
log.Debug("removing files")
if err = c.clean(t, log); err != nil {
log.Errorf("failed to clean torrent files: %q", err)
continue
}
}
}
示例4: GetDetails
// GetDetails helps getting infos for a movie
// If there is an error, it will be of type *errors.Collector
func (m *Movie) GetDetails(log *logrus.Entry) error {
c := errors.NewCollector()
if len(m.Detailers) == 0 {
c.Push(errors.Wrap("No detailer available").Fatal())
return c
}
var done bool
for _, d := range m.Detailers {
detailerLog := log.WithField("detailer", d.Name())
err := d.GetDetails(m, detailerLog)
if err == nil {
done = true
break
}
c.Push(errors.Wrap(err).Ctx("Detailer", d.Name()))
}
if !done {
c.Push(errors.Wrap("All detailers failed").Fatal())
}
if c.HasErrors() {
return c
}
return nil
}
示例5: GetSubtitle
// GetSubtitle implements the subtitle interface
// If there is an error, it will be of type *errors.Collector
func (m *Movie) GetSubtitle(log *logrus.Entry) error {
c := errors.NewCollector()
var subtitle Subtitle
for _, subtitler := range m.Subtitlers {
var err error
subtitlerLog := log.WithField("subtitler", subtitler.Name())
subtitle, err = subtitler.GetMovieSubtitle(m, subtitlerLog)
if err == nil {
break
}
c.Push(errors.Wrap(err).Ctx("Subtitler", subtitler.Name()))
}
if subtitle != nil {
file, err := os.Create(m.File.SubtitlePath())
if err != nil {
c.Push(errors.Wrap(err).Fatal())
return c
}
defer file.Close()
defer subtitle.Close()
if _, err := io.Copy(file, subtitle); err != nil {
c.Push(errors.Wrap(err).Fatal())
return c
}
}
if c.HasErrors() {
return c
}
return nil
}
示例6: Run
// Run runs the safeguard
func (s *Safeguard) Run(log *logrus.Entry) error {
s.wg.Add(1)
defer s.wg.Done()
log = log.WithField("module", "safeguard")
log.Debug("safeguard started")
for {
select {
case <-s.done:
log.Debug("safeguard stopped")
return nil
case <-s.event:
// Increase the event count
s.count++
if s.count >= MaxEventCount {
ctx := errors.Context{
"current_count": s.count,
"max_count": MaxEventCount,
}
return errors.New("got %d safeguard events in less than %s",
s.count, MaxEventDelay).Fatal().AddContext(ctx)
}
case <-time.After(MaxEventDelay):
// Reset the panic count is there was not panic during the
// MaxPanicDelay
s.count = 0
}
}
}
示例7: Watch
// Watch implements the modules fsNotifier interface
func (fs *FsNotify) Watch(watchPath string, ctx polochon.FsNotifierCtx, log *logrus.Entry) error {
// Create a new watcher
watcher, err := fsnotify.NewWatcher()
if err != nil {
return err
}
fs.watcher = watcher
// Ensure that the watch path exists
if _, err := os.Stat(watchPath); os.IsNotExist(err) {
return err
}
log = log.WithField("module", moduleName)
// Run the event handler
go fs.eventHandler(ctx, log)
// Watch the path
if err := fs.watcher.Add(watchPath); err != nil {
return err
}
return nil
}
示例8: reportCompleted
func reportCompleted(client client.Queue, task *TaskRun, log *logrus.Entry) *updateError {
_, err := client.ReportCompleted(task.TaskID, strconv.Itoa(task.RunID))
if err != nil {
log.WithField("error", err).Warn("Not able to report successful completion for task.")
return &updateError{err: err.Error()}
}
return nil
}
示例9: Notify
// Notify sends video to the notifiers
func (o *Organizer) Notify(v polochon.Video, log *logrus.Entry) {
log = log.WithField("function", "notify")
for _, n := range o.config.Notifiers {
if err := n.Notify(v, log); err != nil {
log.Warnf("failed to send a notification from notifier: %q: %q", n.Name(), err)
}
}
}
示例10: DecorateRuntimeContext
// DecorateRuntimeContext appends line, file and function context to the logger
func DecorateRuntimeContext(logger *logrus.Entry) *logrus.Entry {
if pc, file, line, ok := runtime.Caller(1); ok {
fName := runtime.FuncForPC(pc).Name()
return logger.WithField("file", file).WithField("line", line).WithField("func", fName)
} else {
return logger
}
}
示例11: 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
}
示例12: Run
// Run starts the server
func (s *Server) Run(log *logrus.Entry) error {
s.log = log.WithField("app", AppName)
// Init the app
s.InitStart(log)
s.gracefulServer = manners.NewWithServer(s.httpServer(s.log))
return s.gracefulServer.ListenAndServe()
}
示例13: reportException
func reportException(client client.Queue, task *TaskRun, reason runtime.ExceptionReason, log *logrus.Entry) *updateError {
payload := queue.TaskExceptionRequest{Reason: string(reason)}
_, err := client.ReportException(task.TaskID, strconv.Itoa(task.RunID), &payload)
if err != nil {
log.WithField("error", err).Warn("Not able to report exception for task")
return &updateError{err: err.Error()}
}
return 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: 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
}