This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//f represnts io.file | |
// incase I don't need lumberjack and want to | |
// write to both Stdout and file | |
multi := io.MultiWriter(os.Stdout, f) | |
l := ConfigureLogrus(multi) | |
// in case I don't need lumberjack and want to | |
// write to file only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ConfigureLogrus(output io.Writer) *logrus.Logger { | |
logger := logrus.New() | |
logger.SetLevel(logrus.DebugLevel) | |
logger.SetFormatter(&logrus.TextFormatter{ | |
DisableColors: false, | |
FullTimestamp: true, | |
TimestampFormat: "2006-01-02 15:04:05.000", | |
ForceColors: true, | |
DisableLevelTruncation: true, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func configureLogrus(lumberjackConfig *lumberjack.Logger) *logrus.Logger { | |
logger := logrus.New() | |
logger.SetLevel(logrus.DebugLevel) | |
logger.SetFormatter(&logrus.TextFormatter{ | |
DisableColors: false, | |
FullTimestamp: true, | |
TimestampFormat: "2006-01-02 15:04:05.000", | |
ForceColors: true, | |
DisableLevelTruncation: true, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (f FakeResource) Close() error{ | |
var err error | |
//close fake resouce | |
//if fails return error | |
//lets return err here | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FakeResource struct{ | |
//some fake resource | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db, err := sql.Open(confs.DBDriverName, connectionString) | |
if err != nil { | |
log.Fatalln("Problem while setting up the data base ", wErr) | |
} | |
if wErr = db.Ping(); err != nil { | |
log.Fatalln("Problem while pinging to the data base ", err) | |
} | |
defer Close(db) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (db *DB) Close() error { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Close(r io.Closer) { | |
err := r.Close() | |
if err != nil { | |
logger.Errorn("Problem while closing the connection", err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main(){ | |
fileName := "xyz.txt" | |
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0755) | |
if err != nil { | |
if os.IsNotExist(err) { | |
log.Fatalf("Fatal, Problem while opening file %v for logging, err: %v \n", args.logFile, err) | |
} | |
} | |
//----------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Close(r *os.File) { | |
err := r.Close() | |
if err != nil { | |
logger.Errorn("Problem while closing the connection", err) | |
} | |
} |
NewerOlder