Tomo-9925 / cnet

Controlling and logging communication of process in Docker container
2 stars 0 forks source link

本番でのログ出力 #26

Closed Tomo-9925 closed 3 years ago

Tomo-9925 commented 3 years ago
~/g/g/t/c/c/cnet develop* k992077@k992077_sotsuken
❯ sudo ./cnet
INFO[2020-12-06T08:12:41Z] container information fetched                 containers="[{ID:394612b9d950084250a53cecb69ac8dbfd69b48747d302f2d5813d4b185508a4 Name:/nginx_test_invalid} {ID:1868b7ecf330289363efad885473e9dd6b09e640cfb7a34afc73b11825482f93 Name:/nginx_test}]"
INFO[2020-12-06T08:12:41Z] the security policy loaded                    policies="[{Container:{ID: Name:nginx_test} Communications:[{Processes:[{ID:0 Executable: Path:/usr/sbin/nginx}] Sockets:[{Protocol:TCP RemoteIP:<nil> LocalPort:80 RemotePort:0} {Protocol:TCP RemoteIP:<nil> LocalPort:443 RemotePort:0}]}]}]"
INFO[2020-12-06T08:12:41Z] the nfqueue rule added                        chain_name=DOCKER-USER protocol=all queue_num=2 rule_num=1
^CFailed to write to log, write ./cnet.log: file already closed

一部標準出力に出力されるのと,ファイル閉じたあとにログを出力しようとしておりエラーが出てキモい.

masibw commented 3 years ago

了解です!調べますね:+1:

masibw commented 3 years ago
    if !debug {
        err = logFile.Close()
        if err != nil {
            logrus.WithField("error", err).Error("failed to close log file")
        }
    }
    logrus.WithField("logfile", logFile).Infoln("cnet quits")

ここの部分なんですが、どう言った対処が適切だと思います?

Tomo-9925 commented 3 years ago

ファイルに書き込むことにしました.