func (l *AuditLog) EmitAuditEvent(eventType string, fields EventFields) error {
	log.Debugf("auditLog.EmitAuditEvent(%s)", eventType)

	// see if the log needs to be rotated
	if err := l.rotateLog(); err != nil {
		log.Error(err)
	}

	// set event type and time:
	fields[EventType] = eventType
	fields[EventTime] = l.TimeSource().In(time.UTC).Round(time.Second)

	// line is the text to be logged
	line := eventToLine(fields)

	// if this event is associated with a session -> forward it to the session log as well
	sessionID := fields.GetString(SessionEventID)
	if sessionID != "" {
		sl, err := l.LoggerFor(session.ID(sessionID))
		if err == nil {
			sl.LogEvent(fields)

			// Session ended? Get rid of the session logger then:
			if eventType == SessionEndEvent {
				log.Infof("audit log: removing session logger for SID=%v", sessionID)
				l.Lock()
				delete(l.loggers, session.ID(sessionID))
				l.Unlock()
				if err := sl.Finalize(); err != nil {
					log.Error(err)
				}
			}
		}
	}
	// log it to the main log file:
	if l.file != nil {
		fmt.Fprintln(l.file, line)
	}
	return nil
}
// EmitAuditEvent adds a new event to the log. Part of auth.IAuditLog interface.
EmitAuditEvent adds a new event to the log. Part of auth.IAuditLog interface.
// EmitAuditEvent adds a new event to the log . Part of auth . IAuditLog interface .
func (l *AuditLog) EmitAuditEvent(eventType string, fields EventFields) error {
	log.Debugf("auditLog.EmitAuditEvent(%s)", eventType)
	if err := l.rotateLog(); err != nil {
		log.Error(err)
	}
	fields[EventType] = eventType
	fields[EventTime] = l.TimeSource().In(time.UTC).Round(time.Second)
	line := eventToLine(fields)
	sessionID := fields.GetString(SessionEventID)
	if sessionID != "" {
		sl, err := l.LoggerFor(session.ID(sessionID))
		if err == nil {
			sl.LogEvent(fields)
			if eventType == SessionEndEvent {
				log.Infof("audit log: removing session logger for SID=%v", sessionID)
				l.Lock()
				delete(l.loggers, session.ID(sessionID))
				l.Unlock()
				if err := sl.Finalize(); err != nil {
					log.Error(err)
				}
			}
		}
	}
	if l.file != nil {
		fmt.Fprintln(l.file, line)
	}
	return nil
}
func ( l * AuditLog ) EmitAuditEvent ( eventType string , fields EventFields ) error { log . Debugf ( " " , eventType ) if err := l . rotateLog ( ) ; err != nil { log . Error ( err ) } fields [ EventType ] = eventType fields [ EventTime ] = l . TimeSource ( ) . In ( time . UTC ) . Round ( time . Second ) line := eventToLine ( fields ) sessionID := fields . GetString ( SessionEventID ) if sessionID != " " { sl , err := l . LoggerFor ( session . ID ( sessionID ) ) if err == nil { sl . LogEvent ( fields ) if eventType == SessionEndEvent { log . Infof ( " " , sessionID ) l . Lock ( ) delete ( l . loggers , session . ID ( sessionID ) ) l . Unlock ( ) if err := sl . Finalize ( ) ; err != nil { log . Error ( err ) } } } } if l . file != nil { fmt . Fprintln ( l . file , line ) } return nil }
EmitAuditEvent adds a new event to the log.
EmitAuditEvent adds a new event to the log .
// see if the log needs to be rotated // set event type and time: // line is the text to be logged // if this event is associated with a session -> forward it to the session log as well // Session ended? Get rid of the session logger then: // log it to the main log file: