예제 #1
0
파일: file.go 프로젝트: rightscale/rlog
//LaunchModule is intended to run in a separate goroutine and used by rlog internally. It writes log
//messages to file Arguments: [dataChan] Channel to receive log messages. [flushChan] Channel to
//receive flush command
func (conf *fileLogger) LaunchModule(dataChan <-chan (*common.RlogMsg), flushChan chan (chan (bool))) {

	prefix := common.SyslogHeader()

	//Wait forever on data and flush channel
	for {
		select {
		case logMsg := <-dataChan:
			//Received log message, print it
			err := conf.writeMsg(logMsg, prefix)
			if err != nil {
				// we may be able to work around intermittent failures by reopening.
				if conf.reopenFile() != nil {
					err = conf.writeMsg(logMsg, prefix)
				}
			}
			if err != nil {
				// panic if reopening did not resolve the issue.
				panic(err)
			}
		case ret := <-flushChan:
			//Flush and return success
			conf.flush(dataChan, prefix)
			ret <- true
		}
	}
}
예제 #2
0
파일: console.go 프로젝트: rightscale/rlog
// Intended to run in a separate goroutine. It prints log messages to console.
//
// dataChan: receives log messages.
//
// flushChan: receives flush command.
func (conf *ConsoleLogger) LaunchModule(dataChan <-chan (*common.RlogMsg), flushChan chan (chan (bool))) {

	prefix := common.SyslogHeader()

	// wait forever on data and flush channel
	for {
		select {
		case logMsg := <-dataChan:
			// received log message, print it
			conf.printMsg(logMsg, prefix)
		case ret := <-flushChan:
			// flush and return success
			conf.flush(dataChan, prefix)
			ret <- true
		}
	}
}