예제 #1
0
파일: log_file.go 프로젝트: hidu/tool
func SetLogFile(loger *log.Logger, logPath string, log_type LOG_TYPE) error {
	var logFile *os.File
	var err error
	var checkFile = func() error {
		logPathCur := logPath + "." + time.Now().Format(string(log_type))
		if !fs.FileExists(logPathCur) {
			if logFile != nil {
				logFile.Close()
				logFile = nil
			}
			fs.DirCheck(logPathCur)
		}

		if logFile == nil {
			logFile, err = os.OpenFile(logPathCur, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
			if err != nil {
				log.Println("create log file failed [", logPathCur, "]", err)
			}
			loger.SetOutput(logFile)
		}
		return err
	}
	checkFile()
	time_util.SetInterval(func() {
		checkFile()
	}, 1)
	return err
}
예제 #2
0
파일: logging.go 프로젝트: ngenator/slack
func logToFile(logger *log.Logger, filename string) {
	f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		logger.Fatalf("error opening file: %v", err)
	}
	logger.SetOutput(f)
}
예제 #3
0
// CopyLoggerTo arranges for messages to be written to any log.Logger, see
// CopyStandardLogTo for details on behaviour and details
func CopyLoggerTo(name string, logger *stdLog.Logger) {
	sev, ok := severityByName(name)
	if !ok {
		panic(fmt.Sprintf("log.CopyLoggerTo(%q): unrecognized severity name", name))
	}
	// Set a log format that captures the user's file and line:
	//   d.go:23: message
	logger.SetFlags(stdLog.Lshortfile)
	logger.SetOutput(logBridge(sev))
}
예제 #4
0
// openFile is for output log file
func openFile(logger *log.Logger, fileName string) {
	if fileName == "" {
		return
	}

	f, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatal("Error opening file :", err.Error())
	}
	logger.SetOutput(f)
}
예제 #5
0
파일: eslog.go 프로젝트: amundi/eschecker
func writeAndSwap(log *log.Logger, msg string, stderr bool) {
	log.SetOutput(g_rlog)
	log.Printf(msg)
	if g_silent {
		log.SetOutput(ioutil.Discard)
	} else if stderr {
		log.SetOutput(os.Stderr)
	} else {
		log.SetOutput(os.Stdout)
	}
}