'How can I release the lock on log file in code?

InitExecLog('test-log.log')

// exec testing ...

// After completed, how can I release the lock on file 'test-log.log'?

func InitExecLog(logPath string) {
    commConsts.ExecLogDir = logUtils.GetLogDir(workspacePath)
    config := getLogConfig()
    config.EncoderConfig.EncodeLevel = nil

    if commonUtils.IsWin() {
        logPath = filepath.Join("winfile:///", logPath)
        zap.RegisterSink("winfile", newWinFileSink)
    }

    config.OutputPaths = []string{logPath}
    var err error
    logUtils.LoggerExecFile, err = config.Build()
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source