Ejemplo n.º 1
0
func fileLog(dir, date string, level int) log.Logger {
	dir = Project.String("log", "dir") + "/" + dir
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		os.MkdirAll(dir, os.ModePerm)
	}
	file, err := os.OpenFile(dir+"/"+date+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
	if err != nil {
		fmt.Println(err)
		ShutDown()
	}
	logger := log.NewLogger(file, Project.String("server", "name"), level)
	return logger
}
Ejemplo n.º 2
0
func mailLog(date string) log.Logger {
	mail := &writer.Email{
		User:     Project.String("log", "email", "user"),
		Password: Project.String("log", "email", "password"),
		Host:     Project.String("log", "email", "host"),
		To:       Project.String("log", "email", "to"),
		Subject:  Project.String("log", "email", "subject"),
	}

	server := Project.String("server", "name")
	mailLevel := int(Project.Get("log", "email", "level").(float64))
	check := Project.Get("formal").(bool)
	if check {
		if err := mail.SendMail("starting server " + server + "..."); err != nil {
			fmt.Println(err)
			ShutDown()
		}
		return log.NewLogger(&asyncMail{mail}, server, mailLevel)
	}
	return fileLog("email", date, mailLevel)
}