diff --git a/external/cmd/help/main.go b/external/cmd/help/main.go index ff8b63f..f9404c1 100644 --- a/external/cmd/help/main.go +++ b/external/cmd/help/main.go @@ -23,6 +23,8 @@ import ( // TODO put colorscheme, prompting stuff into own packages for use in the other commands. would be good to get off of survey. +// TODO use new lockingwriter for logging in the other external commands + func connectDB() (*sql.DB, error) { db, err := sql.Open("sqlite3", "/town/var/codes/codes.db?mode=rw") if err != nil { @@ -125,7 +127,7 @@ func (p *Prompter) Select(prompt string, opts []string) (int, error) { func _main(cs colorScheme) error { lw := lockingwriter.New() - l := log.New(lw, "help", log.Ldate|log.Ltime|log.LUTC|log.Lshortfile|log.Lmsgprefix) + l := log.New(lw, "help: ", log.Ldate|log.Ltime|log.LUTC|log.Lshortfile|log.Lmsgprefix) db, err := connectDB() if err != nil { diff --git a/external/lockingwriter/lockingwriter.go b/external/lockingwriter/lockingwriter.go index a02c3fb..899143f 100644 --- a/external/lockingwriter/lockingwriter.go +++ b/external/lockingwriter/lockingwriter.go @@ -8,6 +8,8 @@ import ( ) // for now this package defines a writer for use with log.New(). It it intended to be used from the external ssh applications. This logger uses a file lock to allow all the various ssh applications to log to the same file. +// the correct way to do this is to send log events to a daemon +// but i'm trying to cut a corner type LockingWriter struct { path string @@ -20,10 +22,10 @@ const ( func New() *LockingWriter { f, err := os.OpenFile(fp, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0660) - if err != nil { + if err != nil && !os.IsExist(err) { panic(err) } - defer f.Close() + f.Close() return &LockingWriter{ path: fp, @@ -43,7 +45,7 @@ func (l *LockingWriter) Write(p []byte) (n int, err error) { } var f *os.File - f, err = os.OpenFile(l.path, os.O_APPEND|os.O_WRONLY, 0600) + f, err = os.OpenFile(l.path, os.O_APPEND|os.O_WRONLY, 0660) if err != nil { return } @@ -51,5 +53,12 @@ func (l *LockingWriter) Write(p []byte) (n int, err error) { defer f.Close() defer fl.Unlock() - return f.Write(p) + n, err = f.Write(p) + + if err != nil { + panic(err) + } + + return + //return f.Write(p) }