// Fire satisfies the logrus.Hook interface. This impl figures out the file and
// line number of the caller and adds them to the data.
332044
func (hook ContextHook) Fire(entry *logrus.Entry) error {
	pc := make([]uintptr, 3, 3)
	count := runtime.Callers(6, pc)
	for i := 0; i < count; i++ {
		fu := runtime.FuncForPC(pc[i] - 1)
		name := fu.Name()
		if strings.HasPrefix(name, prefix) && !strings.HasPrefix(name, vendorprefix) {
			file, line := fu.FileLine(pc[i] - 1)
			entry.SetField("location", fmt.Sprintf("%s:%d", path.Base(file), line))
			break
		}
	}
	return nil
}
539561
func (e *Event) Fire() bool {
	ret := false
	e.o.Do(func() {
		atomic.StoreInt32(&e.fired, 1)
		close(e.c)
		ret = true
	})
	return ret
}
931905
func (hook *SentryHook) Fire(entry *logrus.Entry) error {
	hook.mu.RLock() // Allow multiple go routines to log simultaneously
	defer hook.mu.RUnlock()

	df := newDataField(entry.Data)

	err, hasError := df.getError()
	var crumbs *Breadcrumbs
	if hasError && hook.StacktraceConfiguration.IncludeErrorBreadcrumb {
		crumbs = &Breadcrumbs{
			Values: []Value{{
				Timestamp: int64(time.Now().Unix()),
				Type:      "error",
				Message:   fmt.Sprintf("%+v", err),
			}},
		}
	}

	packet := raven.NewPacketWithExtra(entry.Message, nil, crumbs)
	packet.Timestamp = raven.Timestamp(entry.Time)
	packet.Level = severityMap[entry.Level]
	packet.Platform = "go"

	// set special fields
	if hook.serverName != "" {
		packet.ServerName = hook.serverName
	}
	if logger, ok := df.getLogger(); ok {
		packet.Logger = logger
	}
	if serverName, ok := df.getServerName(); ok {
		packet.ServerName = serverName
	}
	if eventID, ok := df.getEventID(); ok {
		packet.EventID = eventID
	}
	if tags, ok := df.getTags(); ok {
		packet.Tags = tags
	}
	if fingerprint, ok := df.getFingerprint(); ok {
		packet.Fingerprint = fingerprint
	}
	if req, ok := df.getHTTPRequest(); ok {
		packet.Interfaces = append(packet.Interfaces, req)
	}
	if user, ok := df.getUser(); ok {
		packet.Interfaces = append(packet.Interfaces, user)
	}

	// set stacktrace data
	stConfig := &hook.StacktraceConfiguration
	if stConfig.Enable && entry.Level <= stConfig.Level {
		if err, ok := df.getError(); ok {
			var currentStacktrace *raven.Stacktrace
			currentStacktrace = hook.findStacktrace(err)
			if currentStacktrace == nil {
				currentStacktrace = raven.NewStacktrace(stConfig.Skip, stConfig.Context, stConfig.InAppPrefixes)
			}
			cause := errors.Cause(err)
			if cause == nil {
				cause = err
			}
			exc := raven.NewException(cause, currentStacktrace)
			if !stConfig.SendExceptionType {
				exc.Type = ""
			}
			if stConfig.SwitchExceptionTypeAndMessage {
				packet.Interfaces = append(packet.Interfaces, currentStacktrace)
				packet.Culprit = exc.Type + ": " + currentStacktrace.Culprit()
			} else {
				packet.Interfaces = append(packet.Interfaces, exc)
				packet.Culprit = err.Error()
			}
		} else {
			currentStacktrace := raven.NewStacktrace(stConfig.Skip, stConfig.Context, stConfig.InAppPrefixes)
			if currentStacktrace != nil {
				packet.Interfaces = append(packet.Interfaces, currentStacktrace)
			}
		}
	} else {
		// set the culprit even when the stack trace is disabled, as long as we have an error
		if err, ok := df.getError(); ok {
			packet.Culprit = err.Error()
		}
	}

	// set other fields
	dataExtra := hook.formatExtraData(df)
	if packet.Extra == nil {
		packet.Extra = dataExtra
	} else {
		for k, v := range dataExtra {
			packet.Extra[k] = v
		}
	}

	_, errCh := hook.client.Capture(packet, nil)

	switch {
	case hook.asynchronous:
		// Our use of hook.mu guarantees that we are following the WaitGroup rule of
		// not calling Add in parallel with Wait.
		hook.wg.Add(1)
		go func() {
			if err := <-errCh; err != nil {
				for _, handlerFn := range hook.errorHandlers {
					handlerFn(entry, err)
				}
			}
			hook.wg.Done()
		}()
		return nil
	case hook.Timeout == 0:
		return nil
	default:
		timeout := hook.Timeout
		timeoutCh := time.After(timeout)
		select {
		case err := <-errCh:
			for _, handlerFn := range hook.errorHandlers {
				handlerFn(entry, err)
			}
			return err
		case <-timeoutCh:
			return fmt.Errorf("no response from sentry server in %s", timeout)
		}
	}
}
805345
func (c *Context) Log(data Data) error {
	return c.Logger.Log(c.Merge(data))
}
508645
func (h *LoggingHook) Fire(entry *logrus.Entry) error {
	// Get information about subsystem from logging entry field.
	iSubsystem, ok := entry.Data[logfields.LogSubsys]
	if !ok {
		serializedEntry, err := entry.String()
		if err != nil {
			return fmt.Errorf("log entry cannot be serialized and doesn't contain 'subsys' field")
		}
		return fmt.Errorf("log entry doesn't contain 'subsys' field: %s", serializedEntry)
	}
	subsystem, ok := iSubsystem.(string)
	if !ok {
		return fmt.Errorf("type of the 'subsystem' log entry field is not string but %s", reflect.TypeOf(iSubsystem))
	}

	// Increment the metric.
	h.metric.WithLabelValues(entry.Level.String(), subsystem).Inc()

	return nil
}
468016
func ToLogrus(err error) logrus.Fields {
	result := logrus.Fields{
		"excValue": err.Error(),
		"excType":  fmt.Sprintf("%T", Cause(err)),
		"excText":  fmt.Sprintf("%+v", err),
	}

	// Add the stack info if provided
	if cast, ok := err.(stack.HasStackTrace); ok {
		trace := cast.StackTrace()
		caller := stack.GetLastFrame(trace)
		result["excFuncName"] = caller.Func
		result["excLineno"] = caller.LineNo
		result["excFileName"] = caller.File
	}

	// Add context if provided
	child, ok := err.(HasContext)
	if !ok {
		return result
	}

	// Append the context map to our results
	for key, value := range child.Context() {
		result[key] = value
	}
	return result
}
422649
func (h *Hooks) Fire() {
	h.mu.Lock()
	defer h.mu.Unlock()

	wg := sync.WaitGroup{}

	for _, f := range h.funcs {
		wg.Add(1)
		go func(f func()) {
			f()
			wg.Done()
		}(f)
	}
	wg.Wait()
}
149981
func (hook *contextHook) Fire(entry *log.Entry) error {
	pc := make([]uintptr, 4)
	cnt := runtime.Callers(6, pc)

	for i := 0; i < cnt; i++ {
		fu := runtime.FuncForPC(pc[i] - 1)
		name := fu.Name()
		if !isSkippedPackageName(name) {
			file, line := fu.FileLine(pc[i] - 1)
			entry.Data["file"] = path.Base(file)
			entry.Data["line"] = line
			break
		}
	}
	return nil
}
868196
func (f *firebaseAPI) Call(method, path, auth string, body interface{}, params map[string]string, dest interface{}) error {
	var response *http.Response
	var err error
	retries := 10

	for {
		response, err = doFirebaseRequest(httpClient, method, path, auth, "",
			body, params)
		if err != nil && retries == 0 {
			return err
		} else if err != nil {
			retries--
			log.Println("Retry: ", err)
			continue
		}

		if response.StatusCode >= 400 && retries > 0 {
			retries--
			log.Println("Retry: status code == ", response.StatusCode)
			response.Body.Close()
			continue
		}

		break
	}

	defer response.Body.Close()

	decoder := json.NewDecoder(response.Body)
	if response.StatusCode >= 400 {
		err := &FirebaseError{}
		decoder.Decode(err)
		return err
	}

	if dest != nil && response.ContentLength != 0 {
		err = decoder.Decode(dest)
		if err != nil {
			return err
		}
	}

	return nil
}
577032
func (c *cmd) fireEvent() (string, error) {
	// Create the user event payload
	msg := &rExecEvent{
		Prefix:  c.conf.prefix,
		Session: c.sessionID,
	}
	buf, err := json.Marshal(msg)
	if err != nil {
		return "", err
	}

	// Format the user event
	event := c.apiclient.Event()
	params := &api.UserEvent{
		Name:          "_rexec",
		Payload:       buf,
		NodeFilter:    c.conf.node,
		ServiceFilter: c.conf.service,
		TagFilter:     c.conf.tag,
	}

	// Fire the event
	id, _, err := event.Fire(params, nil)
	return id, err
}
851436
func (l *JSONFileLogger) Log(msg *logger.Message) error {
	l.mu.Lock()
	err := l.writer.WriteLogEntry(msg)
	l.mu.Unlock()
	return err
}
203878
func (sh *SlackrusHook) Fire(e *logrus.Entry) error {
	if sh.Disabled {
		return nil
	}
	
	color := ""
	switch e.Level {
	case logrus.DebugLevel:
		color = "#9B30FF"
	case logrus.InfoLevel:
		color = "good"
	case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
		color = "danger"
	default:
		color = "warning"
	}

	msg := &slack.Message{
		Username:  sh.Username,
		Channel:   sh.Channel,
		IconEmoji: sh.IconEmoji,
		IconUrl:   sh.IconURL,
	}

	attach := msg.NewAttachment()

	newEntry := sh.newEntry(e)
	// If there are fields we need to render them at attachments
	if len(newEntry.Data) > 0 {

		// Add a header above field data
		attach.Text = "Message fields"

		for k, v := range newEntry.Data {
			slackField := &slack.Field{}

			slackField.Title = k
			slackField.Value = fmt.Sprint(v)
			// If the field is <= 20 then we'll set it to short
			if len(slackField.Value) <= 20 {
				slackField.Short = true
			}

			attach.AddField(slackField)
		}
		attach.Pretext = newEntry.Message
	} else {
		attach.Text = newEntry.Message
	}
	attach.Fallback = newEntry.Message
	attach.Color = color

	c := slack.NewClient(sh.HookURL)

	if sh.Asynchronous {
		go c.SendMessage(msg)
		return nil
	}

	return c.SendMessage(msg)
}
61353
func (hooks LevelHooks) Fire(level Level, entry *Entry) error {
	for _, hook := range hooks[level] {
		if err := hook.Fire(entry); err != nil {
			return err
		}
	}

	return nil
}
913907
func (fs *FileSet) LogFiles() []*LogFile {
	var a []*LogFile
	for _, f := range fs.files {
		if f, ok := f.(*LogFile); ok {
			a = append(a, f)
		}
	}
	return a
}
1055659
func (p *SLSHook) Fire(entry *logrus.Entry) (err error) {

	storeName := p.Config.Store

	if len(p.Config.StoreField) > 0 {
		if specStoreName, ok := entry.Data[p.Config.StoreField].(string); ok {
			storeName = specStoreName
		}
	}

	store, storeExist := p.mapStores.Load(storeName)
	if !storeExist {

		newStore, newStoreErr := sls.NewLogStore(storeName, p.project)
		if newStoreErr != nil {
			return newStoreErr
		}
		store, _ = p.mapStores.LoadOrStore(storeName, newStore)
	}

	ignoreToSend := map[string]bool{}

	ignoreToSend[p.Config.Store] = true

	logStore, ok := store.(*sls.LogStore)
	if !ok {
		err = fmt.Errorf("could not convert %s into *sls.LogStore in log store maps", storeName)
		return
	}

	slsLog := &sls.Log{Time: proto.Uint32(uint32(entry.Time.Unix()))}

	var strCtx string

	if len(p.Config.ContextField) > 0 {
		if ctxData, exist := entry.Data[p.Config.ContextField]; exist {

			if ctx, ok := ctxData.(string); ok {
				strCtx = ctx
			} else {
				jsonData, errJson := json.Marshal(ctxData)
				if errJson != nil {
					return errJson
				}

				strCtx = string(jsonData)
			}

			ignoreToSend[p.Config.ContextField] = true

			slsLog.Contents = append(slsLog.Contents,
				&sls.LogContent{
					Key:   proto.String(p.Config.ContextField),
					Value: proto.String(strCtx),
				})

		}
	}

	topic := proto.String(fieldToString(entry, p.Config.TopicField))
	source := proto.String(fieldToString(entry, p.Config.SourceField))

	ignoreToSend[p.Config.TopicField] = true
	ignoreToSend[p.Config.SourceField] = true

	if len(entry.Data) > 0 {
		for k, v := range entry.Data {

			if ignoreToSend[k] {
				continue
			}

			content := &sls.LogContent{
				Key:   proto.String(k),
				Value: proto.String(fmt.Sprintf("%v", v)),
			}

			slsLog.Contents = append(slsLog.Contents, content)
		}
	}

	slsLog.Contents = append(slsLog.Contents,
		&sls.LogContent{
			Key:   proto.String("message"),
			Value: proto.String(entry.Message),
		})

	slsLog.Contents = append(slsLog.Contents,
		&sls.LogContent{
			Key:   proto.String("log_level"),
			Value: proto.String(entry.Level.String()),
		})

	var slsTags []*sls.LogTag

	if len(p.Config.TagsField) > 0 {
		logrusTags, ok := entry.Data[p.Config.TagsField].(map[string]string)

		if ok {
			for k, v := range logrusTags {
				slsTags = append(slsTags,
					&sls.LogTag{
						Key:   proto.String(k),
						Value: proto.String(v),
					})
			}
		}
	}

	logGroup := &sls.LogGroup{
		Topic:   topic,
		Source:  source,
		Logs:    []*sls.Log{slsLog},
		LogTags: slsTags,
	}

	if p.Config.Async {
		go logStore.PutLogs(logGroup)
		return
	}

	err = logStore.PutLogs(logGroup)

	return
}
103199
func (l *loop) logf(isError bool, format string, a ...interface{}) {
	if l.descr == "" {
		return
	}
	if isError {
		logger.Errorf(format, a...)
	} else {
		logger.Infof(format, a...)
	}
}
1218590
func (cl *Call) Log(arguments ...interface{}) {
	cl.scope.log(cl.entry, fmt.Sprintln(arguments...))
}