New configures and returns a new logger. It also kicks off the goroutine that performs the log writing as messages queue.
()
| 59 | // New configures and returns a new logger. It also kicks off the goroutine that |
| 60 | // performs the log writing as messages queue. |
| 61 | func New() *Logger { |
| 62 | l := &Logger{queue: make(chan m, 1024), logs: map[string]l4g.Logger{}} |
| 63 | |
| 64 | fmt.Printf("conf.LOG_OUTPUT: %s\n", conf.LOG_OUTPUT) |
| 65 | |
| 66 | l.logs["access"] = make(l4g.Logger) |
| 67 | if (conf.LOG_OUTPUT == "file") || (conf.LOG_OUTPUT == "both") { |
| 68 | fmt.Printf("conf.PATH_LOGS: %s\n", conf.PATH_LOGS) |
| 69 | accessf := l4g.NewFileLogWriter(conf.PATH_LOGS+"/access.log", false) |
| 70 | if accessf == nil { |
| 71 | fmt.Fprintln(os.Stderr, "ERROR: error creating access log file") |
| 72 | os.Exit(1) |
| 73 | } |
| 74 | if conf.LOG_ROTATE { |
| 75 | l.logs["access"].AddFilter("access", l4g.FINEST, accessf.SetFormat("[%D %T] %M").SetRotate(true).SetRotateDaily(true)) |
| 76 | } else { |
| 77 | l.logs["access"].AddFilter("access", l4g.FINEST, accessf.SetFormat("[%D %T] %M")) |
| 78 | } |
| 79 | } |
| 80 | if (conf.LOG_OUTPUT == "console") || (conf.LOG_OUTPUT == "both") { |
| 81 | l.logs["access"].AddFilter("stdout", l4g.FINEST, l4g.NewConsoleLogWriter()) |
| 82 | } |
| 83 | |
| 84 | l.logs["error"] = make(l4g.Logger) |
| 85 | if (conf.LOG_OUTPUT == "file") || (conf.LOG_OUTPUT == "both") { |
| 86 | |
| 87 | errorf := l4g.NewFileLogWriter(conf.PATH_LOGS+"/error.log", false) |
| 88 | if errorf == nil { |
| 89 | fmt.Fprintln(os.Stderr, "ERROR: error creating error log file") |
| 90 | os.Exit(1) |
| 91 | } |
| 92 | if conf.LOG_ROTATE { |
| 93 | l.logs["error"].AddFilter("error", l4g.FINEST, errorf.SetFormat("[%D %T] [%L] %M").SetRotate(true).SetRotateDaily(true)) |
| 94 | } else { |
| 95 | l.logs["error"].AddFilter("error", l4g.FINEST, errorf.SetFormat("[%D %T] [%L] %M")) |
| 96 | } |
| 97 | } |
| 98 | if (conf.LOG_OUTPUT == "console") || (conf.LOG_OUTPUT == "both") { |
| 99 | l.logs["error"].AddFilter("stderr", l4g.FINEST, l4g.NewConsoleLogWriter()) |
| 100 | } |
| 101 | |
| 102 | l.logs["perf"] = make(l4g.Logger) |
| 103 | if (conf.LOG_OUTPUT == "file") || (conf.LOG_OUTPUT == "both") { |
| 104 | perff := l4g.NewFileLogWriter(conf.PATH_LOGS+"/perf.log", false) |
| 105 | if perff == nil { |
| 106 | fmt.Fprintln(os.Stderr, "ERROR: error creating perf log file") |
| 107 | os.Exit(1) |
| 108 | } |
| 109 | if conf.LOG_ROTATE { |
| 110 | l.logs["perf"].AddFilter("perf", l4g.FINEST, perff.SetFormat("[%D %T] [%L] %M").SetRotate(true).SetRotateDaily(true)) |
| 111 | } else { |
| 112 | l.logs["perf"].AddFilter("perf", l4g.FINEST, perff.SetFormat("[%D %T] [%L] %M")) |
| 113 | } |
| 114 | } |
| 115 | if (conf.LOG_OUTPUT == "console") || (conf.LOG_OUTPUT == "both") { |
| 116 | l.logs["perf"].AddFilter("stdout", l4g.FINEST, l4g.NewConsoleLogWriter()) |
| 117 | } |
| 118 |