In shell, I use go run file > output
, but only fmt.Print are saved into output. All the log.Print still output to the screen! And after I searched on the Internet, I found I can set ouput directory for log, but how can I save both log and fmt in the same file?
如何将fmt.Print和log.Print保存到Golang中的相同文件中
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- duange2971 2015-12-15 16:29关注
The logger writes to STDERR while fmt.PrintXXX functions write to STDOUT.
You have two choices:
1) Capture STDERR to the file.
Bash like shells use:go run file > output 2>&1
2) Set the logger's Output to os.Stdout
Then you run like normal
go run file > output
and both the logger and fmt go to the same place.log.SetOutput(os.StdOut)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 matlab计算中误差
- ¥15 对于相关问题的求解与代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料
- ¥15 使用R语言marginaleffects包进行边际效应图绘制
- ¥20 usb设备兼容性问题
- ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊