generated from moul/golang-repo-template
-
-
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.
Merge pull request #6 from moul/dev/moul/refacto-api
feat: refactor API (addresses #5)
- Loading branch information
Showing
4 changed files
with
304 additions
and
128 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 |
---|---|---|
@@ -1,9 +1,43 @@ | ||
package logman_test | ||
|
||
import "moul.io/logman" | ||
import ( | ||
"fmt" | ||
|
||
"moul.io/logman" | ||
) | ||
|
||
func Example() { | ||
writer, _ := logman.NewWriteCloser("./path/to/logdir/", "my-app") | ||
// new log manager | ||
manager := logman.Manager{ | ||
Path: "./path/to/dir", | ||
MaxFiles: 10, | ||
} | ||
|
||
/* | ||
// cleanup old log files for a specific app name | ||
err := manager.GCWithName("my-app") | ||
checkErr(err) | ||
// cleanup old log files for any app sharing this log directory | ||
err = manager.GC() | ||
checkErr(err) | ||
*/ | ||
|
||
// list existing log files | ||
files, err := manager.Files() | ||
checkErr(err) | ||
fmt.Println(files) | ||
|
||
// - create an WriteCloser | ||
// - automatically delete old log files if it hits a limit | ||
writer, err := manager.New("my-app") | ||
checkErr(err) | ||
defer writer.Close() | ||
writer.Write([]byte("hello world!")) | ||
writer.Write([]byte("hello world!\n")) | ||
} | ||
|
||
func checkErr(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
Oops, something went wrong.