func (h *Handler) Apply(w http.ResponseWriter, t *template.Template, tName string, app interface{}) (err error) { err = t.ExecuteTemplate(w, tName, app) if my, bad := mybad.Check(err, "template execution failure", "name", tName); bad { return my } return nil }
func (lg *Logger) AddFiles(fNames ...string) (*Logger, error) { w, err := FilesWriter(fNames...) if my, bad := mybad.Check(err, "logger addfiles failure"); bad { return nil, my } return lg.AddWriters(w), nil }
// StockFileLogger just logs to the given file with normal // flags and no prefix, returning an error on file failure func StockFileLogger(fName string) (*Logger, error) { w, err := FilesWriter(fName) if my, bad := mybad.Check(err, "stockfilelogger failure"); bad { return nil, my } return New(w, "", log.Ldate|log.Ltime), nil }
// StockErrorFileLogger logs to both stderr and the given file // with normal flags and "ERROR" prefix, returning an error // on file failure func StockErrorFileLogger(fName string) (*Logger, error) { fw, err := FilesWriter(fName) if my, bad := mybad.Check(err, "stockerrorfilelogger failure"); bad { return nil, my } w := io.MultiWriter(fw, os.Stderr) return New(w, "ERROR:", log.Ldate|log.Ltime), nil }
func Test2(t *testing.T) { lg := NewLogger() lg.Println("Shouldn't see this") lg2, err := lg.AddFiles("TESTFILE.txt") if my, bad := mybad.Check(err, "test2 failure"); bad { log.Println(my.MuleError()) return } lg2.Println("Should see this") lg2.Ping() lg3 := lg2.AddStdout() lg3.Ping() testErr := errors.New("TESTERR") if my, bad := mybad.Check(testErr, "test2 check"); bad { lg3.Println(my) } }
func FilesWriter(fNames ...string) (writer io.Writer, err error) { files := make([]io.Writer, len(fNames)) for i, filename := range fNames { xFile, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600) if my, bad := mybad.Check(err, "fileswriter failure", "filename", filename, "package", "mylog"); bad { return nil, my } files[i] = xFile } if len(files) == 1 { return files[0], nil } return io.MultiWriter(files...), nil }
func Must(lg *Logger, err error) *Logger { if my, bad := mybad.Check(err, "Must failure"); bad { panic(my.MuleError()) } return lg }