-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Always default logging to stderr. 2. allow users to overwrite output to stdout or a file. However, to provide defaults, this setting is unexported and has no hooks for globally declared files or env varibles. Users must instead pass a file to the settings struct via a method instead. This PR is to solve concerns about the capacity for discrete logging files to appear on the same machine when the intent is for initialization to use the same file every time. It requires users to be more aware of the file locations they're working with in order to set up clog correctly.
- Loading branch information
1 parent
d74116c
commit e45ccce
Showing
4 changed files
with
94 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package clog | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/alcionai/clues" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSettings_LogToFile(t *testing.T) { | ||
tempDir := t.TempDir() | ||
|
||
table := []struct { | ||
name string | ||
input string | ||
expectErr require.ErrorAssertionFunc | ||
expectOverride string | ||
}{ | ||
{ | ||
name: "empty", | ||
input: "", | ||
expectErr: require.Error, | ||
expectOverride: "", | ||
}, | ||
{ | ||
name: "doesn't exist", | ||
input: filepath.Join(tempDir, "foo", "bar", "baz", "log.log"), | ||
expectErr: require.NoError, | ||
expectOverride: filepath.Join(tempDir, "foo", "bar", "baz", "log.log"), | ||
}, | ||
{ | ||
name: "exists", | ||
input: filepath.Join(tempDir, "log.log"), | ||
expectErr: require.NoError, | ||
expectOverride: filepath.Join(tempDir, "log.log"), | ||
}, | ||
} | ||
for _, test := range table { | ||
t.Run(test.name, func(t *testing.T) { | ||
set, err := Settings{}.LogToFile(test.input) | ||
test.expectErr(t, err, clues.ToCore(err)) | ||
assert.Equal(t, test.expectOverride, set.fileOverride) | ||
}) | ||
} | ||
} |