Beispiel #1
0
func newLogger(endpoint, strLevel, strFacility, tag string) EventLevelLogger {
	// figure priority
	level, err := stringToLevel(strLevel)

	if err != nil {
		panic("Initializing in ln logger: " + err.Error())
	}

	// figure out endpoint
	if strings.ToLower(endpoint) == "stderr" {
		// create a logger that writes to stderr, and we dont' care about the facility
		return newJSONLogger(newWriterLogger(os.Stderr, tag), level, -1)
	} else if strings.ToLower(endpoint) == "syslog" {
		facility, err := stringToFacility(strFacility)

		if err != nil {
			panic("Initializing in ln logger : " + err.Error())
		}

		syslogger := newBSyslogger(bsyslog.Priority(facility), tag)
		return newJSONLogger(syslogger, level, facility)
	} else {
		file, err := os.OpenFile(endpoint, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
		if err != nil {
			panic("Initializing ln logger: could not create endpoint " + endpoint + ", error: " + err.Error())
		}
		return newJSONLogger(newWriterLogger(file, tag), level, -1)
	}
}
Beispiel #2
0
func ExampleNewBSyslogger() {
	priority := bsyslog.Priority(syslog.LOG_CRIT | syslog.LOG_AUTH)
	syslogger := newBSyslogger(priority, "example app")
	syslogger.Info("hello world")
}