Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not use '>' or '>>' to write to file from log.Println() and log.Printf()

Tags:

unix

logging

go

I try to write to file using >> as usual by for Go project, It does not work.

./main >> info.log or go run main.go >> info.log

I'm running as root and I've tried to change file permission to 755 but still noting in info.log. I've also tried ls >> ls.log It works fine. So I think there is something wrong with my code. All I use are log.Println() and log.Printf()

My code runs on Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic x86_64)

like image 377
Methuz Kaewsai-kao Avatar asked Nov 15 '25 21:11

Methuz Kaewsai-kao


1 Answers

Go's standard logger writes to stderr. You should either use 2> and 2>> and their friends in your shell scripts, or create your own logger that writes to stdout.

like image 183
Ainar-G Avatar answered Nov 17 '25 12:11

Ainar-G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!