@@ -24,6 +24,7 @@ type Log struct {
2424 Filename string `json:"filename,omitempty"`
2525 Status bool `json:"status,omitempty"`
2626 PrintToTerm bool `json:"print_to_term,omitempty"`
27+ Overwrite bool `json:"overwrite,omitempty"`
2728}
2829
2930// String converts our Log struct into a JSON string
@@ -36,7 +37,7 @@ func (l *Log) String() string {
3637}
3738
3839// New creates a new Log instance given filename
39- func New (filename string ) (* Log , error ) {
40+ func New (filename string , printToTerm bool , overwrite bool ) (* Log , error ) {
4041 // if filename is empty, create a local log where executable is
4142 if filename == "" {
4243 absPath , err := os .Executable ()
@@ -48,10 +49,17 @@ func New(filename string) (*Log, error) {
4849
4950 L := Log {
5051 Filename : filename ,
51- PrintToTerm : false ,
52+ PrintToTerm : printToTerm ,
53+ Overwrite : overwrite ,
5254 }
5355
54- logFile , err := os .OpenFile (L .Filename , os .O_WRONLY | os .O_CREATE | os .O_APPEND , 0755 )
56+ flags := os .O_WRONLY | os .O_CREATE | os .O_APPEND
57+ if L .Overwrite {
58+ flags = os .O_WRONLY | os .O_CREATE | os .O_TRUNC
59+ }
60+
61+ logFile , err := os .OpenFile (L .Filename , flags , 0755 )
62+
5563 if err != nil {
5664 return nil , err
5765 }
0 commit comments