本文整理汇总了Golang中github.com/Sirupsen/logrus.Entry类的典型用法代码示例。如果您正苦于以下问题:Golang Entry类的具体用法?Golang Entry怎么用?Golang Entry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Entry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: searchByImdbID
// searchByImdbID searches on tmdb based on the imdb id
func (t *TmDB) searchByImdbID(m *polochon.Movie, log *logrus.Entry) error {
// No imdb id, no search
if m.ImdbID == "" {
return ErrNoMovieImDBID
}
// ID already found
if m.TmdbID != 0 {
return nil
}
// Search on tmdb
results, err := tmdbSearchByImdbID(t.client, m.ImdbID, "imdb_id", map[string]string{})
if err != nil {
return err
}
// Check if there is any results
if len(results.MovieResults) == 0 {
log.Debugf("Failed to find movie from imdb ID %q", m.ImdbID)
return ErrNoMovieFound
}
m.TmdbID = results.MovieResults[0].ID
log.Debugf("Found movie from imdb ID %q", m.ImdbID)
return nil
}
示例2: 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,
})
}
示例3: 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")
}
示例4: RemoveSeason
// RemoveSeason removes the season from the index
func (si *ShowIndex) RemoveSeason(show *polochon.Show, season int, log *logrus.Entry) error {
log.Infof("Deleting whole season %d of %s from index", season, show.ImdbID)
delete(si.shows[show.ImdbID].Seasons, season)
return nil
}
示例5: send
func (s *fileSender) send(entry *logrus.Entry) (err error) {
msg, err := entry.String()
if err != nil {
return
}
file, err := os.OpenFile(utils.GetLogPath(),
os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
err = &WriteError{
errors.Wrap(err, "logger: Failed to open log file"),
}
return
}
defer file.Close()
_, err = file.WriteString(msg)
if err != nil {
err = &WriteError{
errors.Wrap(err, "logger: Failed to write to log file"),
}
return
}
return
}
示例6: 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
}
}
示例7: Fire
func (h *StreamHook) Fire(entry *logrus.Entry) error {
h.Lock()
defer h.Unlock()
var line string
var err error
if line, err = entry.String(); err != nil {
if h.debug {
fmt.Fprintf(os.Stderr, "Unable to read entry: %v\n", err)
}
return err
}
if h.terminator != "" {
line += h.terminator
}
if _, err := h.writer.WriteString(line); err != nil {
if h.debug {
fmt.Fprintf(os.Stderr, "Unable to write the content: %v\n", err)
}
return err
}
if err := h.writer.Flush(); err != nil {
if h.debug {
fmt.Fprintf(os.Stderr, "Unable to flush the buffer: %v\n", err)
}
return err
}
return nil
}
示例8: eventHandler
func (fs *FsNotify) eventHandler(ctx polochon.FsNotifierCtx, log *logrus.Entry) {
// Notify the waitgroup
ctx.Wg.Add(1)
defer ctx.Wg.Done()
// Close the watcher when done
defer fs.watcher.Close()
for {
select {
case <-ctx.Done:
log.Debug("fsnotify is done watching")
return
case ev := <-fs.watcher.Events:
if ev.Op != fsnotify.Create && ev.Op != fsnotify.Chmod {
continue
}
// Wait for the delay time before sending an event.
// Transmission creates the folder and move the files afterwards.
// We need to wait for the file to be moved in before sending the
// event. Delay is the estimated time to wait.
go func() {
time.Sleep(DELAY)
ctx.Event <- ev.Name
}()
case err := <-fs.watcher.Errors:
log.Error(err)
}
}
}
示例9: 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)
}
示例10: 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)
}
示例11: Fire
// Open the file, write to the file, close the file.
// Whichever user is running the function needs write permissions to the file or directory if the file does not yet exist.
func (hook *lfsHook) Fire(entry *logrus.Entry) error {
var (
fd *os.File
path string
msg string
err error
ok bool
)
if path, ok = hook.paths[entry.Level]; !ok {
err = fmt.Errorf("no file provided for loglevel: %d", entry.Level)
log.Println(err.Error())
return err
}
fd, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
log.Println("failed to open logfile:", path, err)
return err
}
defer fd.Close()
msg, err = entry.String()
if err != nil {
log.Println("failed to generate string for entry:", err)
return err
}
fd.WriteString(msg)
return nil
}
示例12: 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
}
示例13: 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
}
示例14: 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
}
示例15: 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
}