golang/glog bug: Using --log_dir with relative paths creates incorrect symlinks

378 views
Skip to first unread message

Hochhaus, Andrew

unread,
Jul 18, 2013, 4:14:13 PM7/18/13
to golan...@googlegroups.com
Hello,

Thanks for releasing golang/glog. When using the --log_dir flag with a relative path, such as:

$ ./bin/index --log_dir=out/log

The helper symlinks (eg: *.INFO) are created incorrectly. For example:

$ ls -l out/log/index.*
-rw-r--r-- 1 ahochhaus ahochhaus  820851 Jul 18 16:02 out/log/index.ahochhaus-pc.ahochhaus.log.INFO.20130718-160008.30243
lrwxrwxrwx 1 ahochhaus ahochhaus      67 Jul 18 16:00 out/log/index.INFO -> out/log/index.ahochhaus-pc.ahochhaus.log.INFO.20130718-160008.30243


To resolve correctly, the symlink should not include the relative path but only the file name (as the symlink itself and the file being linked to are in the same directory).

Thanks,
-Andy

Hochhaus, Andrew

unread,
Oct 7, 2013, 12:51:29 PM10/7/13
to golan...@googlegroups.com
From the glang/glog README I understand that the master copy of the repository lives inside Google, not on github so I should not send a pull request. This two line change fixes the creation of symlinks when specifying relative --log_dir. Would someone who has access to the internal repository be willing to consider applying this?

diff --git a/src/github.com/golang/glog/glog_file.go b/src/github.com/golang/glog/glog_file.go
index 8dcb2bc..65075d2 100644
--- a/src/github.com/golang/glog/glog_file.go
+++ b/src/github.com/golang/glog/glog_file.go
@@ -114,8 +114,8 @@ func create(tag string, t time.Time) (f *os.File, filename string, err error) {
                f, err := os.Create(fname)
                if err == nil {
                        symlink := filepath.Join(dir, link)
-                       os.Remove(symlink)         // ignore err
-                       os.Symlink(fname, symlink) // ignore err
+                       os.Remove(symlink)        // ignore err
+                       os.Symlink(name, symlink) // ignore err
                        return f, fname, nil
                }
                lastErr = err


Thanks,
-Andy

David Symonds

unread,
Oct 7, 2013, 8:12:06 PM10/7/13
to Hochhaus, Andrew, golang-nuts
I'll take a look.

David Symonds

unread,
Oct 8, 2013, 5:23:07 PM10/8/13
to Hochhaus, Andrew, golang-nuts
Reply all
Reply to author
Forward
0 new messages