-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add logger for pow events (#210)
* feat: add logger for pow events * feat: add error checking when setting up requests and improve on error messages * feat: add a generic post client to send json to a url * refactor: update to generic post client * refactor: update to generic post client
- Loading branch information
Showing
3 changed files
with
85 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package powLogs | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/lilypad-tech/lilypad/pkg/http" | ||
) | ||
|
||
type PowLog struct { | ||
POWTime string // YYYY-MM-DD HH::MM:ss (triggers are every hour on the hour and randomly within the hour) | ||
// t := time.Now(); t.Format(time.RFC3339) | ||
Caller string // cron or rp | ||
CallerID string // cron or rp public address | ||
Step string // text instead of numbers, this way we can query by giving a sort order to the events if we know all the steps, and we do not need to reorder all events if we add one in between | ||
Payload string // a json payload | ||
Status string // log/info/warn/error a way to split an event payload into multiple entries to then be able to filter logs | ||
} | ||
|
||
const namespace = "pow-logs" | ||
const eventsEndpoint = "events" | ||
|
||
var host = os.Getenv("API_HOST") | ||
|
||
func TrackEvent(data PowLog) { | ||
if host == "" { | ||
return | ||
} | ||
|
||
var url = host + namespace + "/" + eventsEndpoint | ||
byts, _ := json.Marshal(data) | ||
payload := string(byts) | ||
|
||
http.GenericJSONPostClient(url, payload) | ||
} |