// Event queues a message at the given level.
// Additional fields may be provided, which will be recursively copied at the time of the function call, and provided to the destination output handler.
// It returns an event Id that can be used with Sync().
512707
func (logger *Logger) Event(level event.Level, message string, fields ...interface{}) uint64 {
	var eventFields interface{}
	if len(fields) > 1 {
		eventFields = fields
	} else if len(fields) == 1 {
		eventFields = fields[0]
	} else if len(fields) == 0 {
		eventFields = nil
	}

	getStack := int32(level) >= atomic.LoadInt32(&logger.stackMinLevel)
	//TODO do we want to just remove the id param from event.New()?
	logEvent := event.New(0, level, message, eventFields, getStack)

	return logger.SendEvent(logEvent)
}
215755
func (h *Handler) HandleEvent(e *events.Event) {
	f := fmtPool.Get().(*formatter)
	f.buffer.Reset()
	f.emitter.Reset(&f.buffer)

	f.level = "INFO"
	f.time = e.Time
	f.message = e.Message
	f.data.args = e.Args
	f.info.Source = e.Source
	f.info.Program = h.Program
	f.info.Pid = h.Pid

	if e.Debug {
		f.level = "DEBUG"
	}

	for _, a := range e.Args {
		if err, ok := a.Value.(error); ok {
			f.level = "ERROR"
			f.info.Errors = append(f.info.Errors, makeEventError(err))
		}
	}

	(objconv.Encoder{Emitter: &f.emitter}).Encode(f.value)
	f.buffer.WriteByte('\n')

	h.mutex.Lock()
	h.Output.Write(f.buffer.b)
	h.mutex.Unlock()

	f.info.Source = ""
	f.info.Errors = f.info.Errors[:0]
	fmtPool.Put(f)
}
652462
func (srv *Instance) PublishEvent(e lifecycle.Event) error {
	return lifecycle.PublishEvent(e, srv.connector)
}
645372
func (h EventHandlerFunc) HandleEvent(ctx context.Context, e Event) error {
	return h(ctx, e)
}
130671
func (h *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
	h.inbox <- event
	return nil
}
43277
func (g *GitHttp) event(e Event) {
	if g.EventHandler != nil {
		g.EventHandler(e)
	} else {
		fmt.Printf("EVENT: %q\n", e)
	}
}
1169551
func (es *EventSource) SendEvent(id uint64, event string, data interface{}) error {
	switch data.(type) {
	case string:
		es.conn.Write(generateMessage(id, event, data.(string)))
	case []byte:
		es.conn.Write(generateMessage(id, event, string(data.([]byte))))
	case EventData:
		content, err := data.(EventData).Encode()
		if err != nil {
			return err
		}
		es.conn.Write(generateMessage(id, event, string(content)))
	}
	return nil
}
1212174
func LogEvent(logger Logger, event *logutilpb.Event) {
	switch event.Level {
	case logutilpb.Level_INFO:
		logger.InfoDepth(1, EventString(event))
	case logutilpb.Level_WARNING:
		logger.WarningDepth(1, EventString(event))
	case logutilpb.Level_ERROR:
		logger.ErrorDepth(1, EventString(event))
	case logutilpb.Level_CONSOLE:
		// Note we can't just pass the string, because it might contain '%'.
		logger.Printf("%s", EventString(event))
	}
}
293101
func event(out io.Writer) {
	event_h := readHeader("event")

	// Event is implemented by hand in wrappers.go

	// Get all the pn_event_type_t enum values
	var etypes []eventType
	enums := findEnums(event_h)
	for _, e := range enums[0].Values {
		if skipEventRe.FindStringSubmatch(e) == nil {
			etypes = append(etypes, newEventType(e))
		}
	}

	doTemplate(out, etypes, `
type EventType int
const ({{range .}}
	 E{{.Name}} EventType = C.{{.Cname}}{{end}}
)
`)

	doTemplate(out, etypes, `
func (e EventType) String() string {
	switch e {
{{range .}}
	case C.{{.Cname}}: return "{{.Name}}"{{end}}
	}
	return "Unknown"
}
`)
}
852594
func (sw *SplunkHandler) Event(logEvent *event.Event) error {
	splunkURL, _ := url.Parse(sw.url.String())
	values := splunkURL.Query()
	values.Set("host", sw.Hostname)
	values.Set("source", sw.Source)
	values.Set("sourcetype", sw.SourceType)
	values.Set("index", sw.Index)
	splunkURL.RawQuery = values.Encode()
	splunkURL.Path = splunkURL.Path + "services/receivers/simple"

	sessionKey, err := sw.getSessionKey()
	if err != nil {
		return err
	}

	var templateBuffer bytes.Buffer
	sw.Template.Execute(&templateBuffer, formatter.EventFormatter(logEvent))
	eventBytes := templateBuffer.Bytes()
	eventBytes = bytes.Replace(eventBytes, []byte{'\n'}, []byte{'\r'}, -1)

	req, _ := http.NewRequest("POST", splunkURL.String(), bytes.NewReader(eventBytes))
	req.Header.Set("Authorization", "Splunk "+sessionKey)
	//req.Write(os.Stderr)
	//return nil

	resp, err := sw.client.Do(req)
	if err != nil {
		return err
	}
	resp.Body.Close()

	return nil
}
751534
func ControlEvent(v interface{}) *Event {
	event := NewEvent(v)
	event.Control = true
	return event
}
1286296
func (m *EventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
	if m.Err != nil {
		return m.Err
	}
	m.Events = append(m.Events, event)
	m.Context = ctx
	m.Time = time.Now()
	m.Recv <- event
	return nil
}
1028482
func (il *ILertNotifier) sendEvent(event iLertEvent) error {
	body, err := json.Marshal(event)
	if err != nil {
		return err
	}

	res, err := http.Post(apiEndpoint, "application/json", bytes.NewBuffer(body))
	if err != nil {
		return err
	}

	defer res.Body.Close()

	if res.StatusCode != 200 {
		body, _ := ioutil.ReadAll(res.Body)
		return errors.New(fmt.Sprintf("Unexpected HTTP status code: %d (%s)", res.StatusCode, string(body)))
	}

	return nil
}
962663
func (a *EventCounter) Events(now time.Time, count int64) int64 {
	for {
		nsSince := now.Sub(a.startingTime).Nanoseconds()
		prevNsSinceStart := atomic.LoadInt64(&a.nsSinceStart)
		if nsSince-prevNsSinceStart >= a.eventDuration.Nanoseconds() {
			//		 Note: There is an accepted race here when we transition states that could cause us to
			//		       rarely miss an event that crosses the threshold.  This is an accepted aspect of
			//		       having a very fast non threshold event
			if atomic.CompareAndSwapInt64(&a.nsSinceStart, prevNsSinceStart, nsSince) {
				atomic.StoreInt64(&a.eventsThisPeriod, 0)
				break
			}
		} else {
			break
		}
	}
	return atomic.AddInt64(&a.eventsThisPeriod, count)
}
628807
func (r *Runc) Events(context context.Context, id string, interval time.Duration) (chan *Event, error) {
	cmd := r.command(context, "events", fmt.Sprintf("--interval=%ds", int(interval.Seconds())), id)
	rd, err := cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	ec, err := Monitor.Start(cmd)
	if err != nil {
		rd.Close()
		return nil, err
	}
	var (
		dec = json.NewDecoder(rd)
		c   = make(chan *Event, 128)
	)
	go func() {
		defer func() {
			close(c)
			rd.Close()
			Monitor.Wait(cmd, ec)
		}()
		for {
			var e Event
			if err := dec.Decode(&e); err != nil {
				if err == io.EOF {
					return
				}
				e = Event{
					Type: "error",
					Err:  err,
				}
			}
			c <- &e
		}
	}()
	return c, nil
}
1081659
func (c *CircularBuffer) Events() []Event {
	c.Lock()
	defer c.Unlock()
	return c.eventsCopy()
}
18745
func NewEvent(title, text string) *Event {
	return &Event{
		Title: title,
		Text:  text,
	}
}