forked from gojue/ecapture
-
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.
* log: added function time Signed-off-by: h0x0er <jatink843@protonmail.com> * cmd_handler: loading modules in threads Signed-off-by: h0x0er <jatink843@protonmail.com> * refactor Signed-off-by: h0x0er <jatink843@protonmail.com> * refactor Signed-off-by: h0x0er <jatink843@protonmail.com> * refactor Signed-off-by: h0x0er <jatink843@protonmail.com> * refactor Signed-off-by: h0x0er <jatink843@protonmail.com> * improved daemon logging Signed-off-by: h0x0er <jatink843@protonmail.com> * refactor Signed-off-by: h0x0er <jatink843@protonmail.com> * cmd_handler: logging load times Signed-off-by: h0x0er <jatink843@protonmail.com> * fix Signed-off-by: h0x0er <jatink843@protonmail.com> * checking tracked in tls Signed-off-by: h0x0er <jatink843@protonmail.com> * improved logging function execution time Signed-off-by: h0x0er <jatink843@protonmail.com> * improvements Signed-off-by: h0x0er <jatink843@protonmail.com> --------- Signed-off-by: h0x0er <jatink843@protonmail.com>
- Loading branch information
Showing
6 changed files
with
77 additions
and
17 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,38 @@ | ||
package daemon | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"sync" | ||
"time" | ||
) | ||
|
||
var logMutex sync.Mutex | ||
|
||
func writeLog(message string) { | ||
logMutex.Lock() | ||
defer logMutex.Unlock() | ||
|
||
f, _ := os.OpenFile("/home/agent/daemon.log", | ||
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
|
||
defer f.Close() | ||
|
||
//This is to prevent printing time for a newline | ||
if message == "\n" { | ||
f.WriteString(fmt.Sprintf("\n")) | ||
} else { | ||
location, _ := time.LoadLocation("Etc/GMT") | ||
f.WriteString(fmt.Sprintf("%s:%s\n", time.Now().In(location).Format("Mon, 02 Jan 2006 15:04:05 MST"), message)) | ||
} | ||
} | ||
|
||
func dLog(kind string, what string) { | ||
logStr := fmt.Sprintf("[%s] %s", kind, what) | ||
log.Print(logStr) | ||
} | ||
|
||
func LogTime(flag string, start time.Time, end time.Time) { | ||
go writeLog(fmt.Sprintf("[%s] Took %f seconds", flag, end.Sub(start).Seconds())) | ||
} |
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