This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from bobmcn/hotfix/force-new-file
Add an option to New that will always create a new file.
- Loading branch information
Showing
6 changed files
with
214 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package rotatelogs_test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
rotatelogs "github.com/lestrrat-go/file-rotatelogs" | ||
) | ||
|
||
func ExampleForceNewFile () { | ||
logDir, err := ioutil.TempDir("", "rotatelogs_test") | ||
if err != nil { | ||
fmt.Println("could not create log directory ", err) | ||
return | ||
} | ||
logPath := fmt.Sprintf("%s/test.log", logDir) | ||
|
||
for i := 0; i < 2; i++ { | ||
writer, err := rotatelogs.New(logPath, | ||
rotatelogs.ForceNewFile(), | ||
) | ||
if err != nil { | ||
fmt.Println("Could not open log file ", err) | ||
return | ||
} | ||
|
||
n, err := writer.Write([]byte("test")) | ||
if err != nil || n != 4 { | ||
fmt.Println("Write failed ", err, " number written ", n) | ||
return | ||
} | ||
err = writer.Close() | ||
if err != nil { | ||
fmt.Println("Close failed ", err) | ||
return | ||
} | ||
} | ||
|
||
files, err := ioutil.ReadDir(logDir) | ||
if err != nil { | ||
fmt.Println("ReadDir failed ", err) | ||
return | ||
} | ||
for _, file := range files { | ||
fmt.Println(file.Name(), file.Size()) | ||
} | ||
|
||
err = os.RemoveAll(logDir) | ||
if err != nil { | ||
fmt.Println("RemoveAll failed ", err) | ||
return | ||
} | ||
// OUTPUT: | ||
// test.log 4 | ||
// test.log.1 4 | ||
} |
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