func (l *AuditLog) LoggerFor(sid session.ID) (sl *SessionLogger, err error) {
	l.Lock()
	defer l.Unlock()

	sl, ok := l.loggers[sid]
	if ok {
		return sl, nil
	}
	// make sure session logs dir is present
	sdir := filepath.Join(l.dataDir, SessionLogsDir)
	if err := os.MkdirAll(sdir, 0770); err != nil {
		log.Error(err)
		return nil, trace.Wrap(err)
	}
	// create a new session stream file:
	fstream, err := os.OpenFile(l.sessionStreamFn(sid), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
	if err != nil {
		log.Error(err)
		return nil, trace.Wrap(err)
	}
	// create a new session file:
	fevents, err := os.OpenFile(l.sessionLogFn(sid), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
	if err != nil {
		log.Error(err)
		return nil, trace.Wrap(err)
	}
	sl = &SessionLogger{
		sid:         sid,
		streamFile:  fstream,
		eventsFile:  fevents,
		timeSource:  l.TimeSource,
		createdTime: l.TimeSource().In(time.UTC).Round(time.Second),
	}
	l.loggers[sid] = sl
	return sl, nil
}
// LoggerFor creates a logger for a specified session. Session loggers allow
// to group all events into special "session log files" for easier audit
LoggerFor creates a logger for a specified session. Session loggers allow
to group all events into special "session log files" for easier audit
// LoggerFor creates a logger for a specified session . Session loggers allow // to group all events into special " session log files " for easier audit
func (l *AuditLog) LoggerFor(sid session.ID) (sl *SessionLogger, err error) {
	l.Lock()
	defer l.Unlock()
	sl, ok := l.loggers[sid]
	if ok {
		return sl, nil
	}
	sdir := filepath.Join(l.dataDir, SessionLogsDir)
	if err := os.MkdirAll(sdir, 0770); err != nil {
		log.Error(err)
		return nil, trace.Wrap(err)
	}
	fstream, err := os.OpenFile(l.sessionStreamFn(sid), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
	if err != nil {
		log.Error(err)
		return nil, trace.Wrap(err)
	}
	fevents, err := os.OpenFile(l.sessionLogFn(sid), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
	if err != nil {
		log.Error(err)
		return nil, trace.Wrap(err)
	}
	sl = &SessionLogger{
		sid:         sid,
		streamFile:  fstream,
		eventsFile:  fevents,
		timeSource:  l.TimeSource,
		createdTime: l.TimeSource().In(time.UTC).Round(time.Second),
	}
	l.loggers[sid] = sl
	return sl, nil
}
func ( l * AuditLog ) LoggerFor ( sid session . ID ) ( sl * SessionLogger , err error ) { l . Lock ( ) defer l . Unlock ( ) sl , ok := l . loggers [ sid ] if ok { return sl , nil } sdir := filepath . Join ( l . dataDir , SessionLogsDir ) if err := os . MkdirAll ( sdir , 0770 ) ; err != nil { log . Error ( err ) return nil , trace . Wrap ( err ) } fstream , err := os . OpenFile ( l . sessionStreamFn ( sid ) , os . O_WRONLY | os . O_CREATE | os . O_APPEND , 0640 ) if err != nil { log . Error ( err ) return nil , trace . Wrap ( err ) } fevents , err := os . OpenFile ( l . sessionLogFn ( sid ) , os . O_WRONLY | os . O_CREATE | os . O_APPEND , 0640 ) if err != nil { log . Error ( err ) return nil , trace . Wrap ( err ) } sl = & SessionLogger { sid : sid , streamFile : fstream , eventsFile : fevents , timeSource : l . TimeSource , createdTime : l . TimeSource ( ) . In ( time . UTC ) . Round ( time . Second ) , } l . loggers [ sid ] = sl return sl , nil }
LoggerFor creates a logger for a specified session.
LoggerFor creates a logger for a specified session .
// make sure session logs dir is present // create a new session stream file: // create a new session file: