Exemple #1
0
// serveLogLevel sets the log level of the server
func (h *Handler) serveLogLevel(w http.ResponseWriter, r *http.Request) {
	l := r.URL.Query().Get("level")
	err := wlog.SetLevelFromName(l)
	if err != nil {
		HttpError(w, err.Error(), true, http.StatusBadRequest)
	}
}
Exemple #2
0
func (s *Service) Open() error {
	switch s.c.File {
	case "STDERR":
		s.f = &nopCloser{f: s.stderr}
	case "STDOUT":
		s.f = &nopCloser{f: s.stdout}
	default:
		dir := path.Dir(s.c.File)
		if _, err := os.Stat(dir); os.IsNotExist(err) {
			err := os.MkdirAll(dir, 0755)
			if err != nil {
				return err
			}
		}

		f, err := os.OpenFile(s.c.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0640)
		if err != nil {
			return err
		}
		s.f = f
	}

	wlog.SetLevelFromName(s.c.Level)
	return nil
}