After build to file. I run it by daemonize with command
daemonize /var/www/repo/bin/tracking_api 1>> /var/www/repo/bin/tracking_api.log
I see it generate a new file but nothing in that file. In code I log.Print a lot.
I just know basic about GO, please guide me to log that. Is there any easier way to run golang to server instead of using daemonize?
Go logger logs to standard error, redirect standard error and it will work fine.
/var/www/repo/bin/tracking_api 2>&1 >> /var/www/repo/bin/tracking_api.log
Unfortunately, daemonize
tool closes standard input, output and error so the only solution is to change the log file with SetOutput function.
nohup /var/www/repo/bin/tracking_api > /var/www/repo/bin/tracking_api.log &
You could use immortal basically is a supervisor, you can either use it like this:
immortal -l /var/www/repo/bin/tracking_api.log tracking_api
or by a configuration YAML file which gives you more options, for example:
cmd: tracking_api
log:
file: /var/www/repo/bin/tracking_api.log
age: 86400 # seconds
num: 7 # int
size: 1 # MegaBytes
timestamp: true # will add timesamp to log
If you would like to keep also the standard error output in a separate file you could use something like:
cmd: tracking_api
log:
file: /var/www/repo/bin/tracking_api.log
age: 86400 # seconds
num: 7 # int
size: 1 # MegaBytes
stderr:
file: /var/www/repo/bin/tracking_api.log
age: 86400 # seconds
num: 7 # int
size: 1 # MegaBytes
timestamp: true # will add timesamp to log