Ejemplo n.º 1
0
func main() {
	defer crash.HandleAll()
	srvApp.Init()
	srvApp.Run()
}
Ejemplo n.º 2
0
Archivo: flog.go Proyecto: xaevman/log
// New returns a new FLog instance of the requested type. The backing log file is
// created or opened for append.
func New(name, logPath string, logType int) FLog {
	var newLog FLog

	mkdir(logPath)

	f, err := os.OpenFile(
		path.Join(logPath, name+".log"),
		FLogOpenFlags,
		0660,
	)
	if err != nil {
		return nil
	}

	switch logType {
	case BufferedFile:

		bLog := BufferedLog{
			baseDir:  logPath,
			chClose:  make(chan interface{}, 0),
			enabled:  true,
			flushSec: DefaultFlushIntervalSec,
			name:     name,
		}

		bLog.file = f

		l := log.New(&bLog.buffer, "", 0)
		bLog.logger = l

		go func() {
			defer crash.HandleAll()
			bLog.asyncFlush()
		}()

		newLog = &bLog
		break

	case DirectFile:

		dLog := DirectLog{
			baseDir: logPath,
			enabled: true,
			name:    name,
		}

		dLog.file = f

		l := log.New(dLog.file, "", 0)
		dLog.logger = l

		newLog = &dLog
		break
	}

	initMsg := xlog.NewLogMsg(
		name,
		"==== Log init ====",
		2,
	)

	newLog.Print(initMsg)

	return newLog
}