Client to log if URL is empty.

master
J. David Lee 2019-06-11 20:07:43 +02:00
parent f1200c0d7c
commit 0b62cbd57d
1 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package amclient
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"time"
@ -36,6 +37,10 @@ func (client Client) post(values url.Values) error {
}
func (cl Client) Ping() error {
if cl.reportURL == "" {
log.Printf("AM ping")
return nil
}
return cl.post(url.Values{
"action": []string{"ping"},
})
@ -43,6 +48,10 @@ func (cl Client) Ping() error {
func (cl Client) Log(text string, args ...interface{}) error {
text = fmt.Sprintf(text, args...)
if cl.reportURL == "" {
log.Printf("AM log: %s", text)
return nil
}
return cl.post(url.Values{
"action": []string{"log"},
"text": []string{text},
@ -51,6 +60,10 @@ func (cl Client) Log(text string, args ...interface{}) error {
func (cl Client) Alert(text string, args ...interface{}) error {
text = fmt.Sprintf(text, args...)
if cl.reportURL == "" {
log.Printf("AM alert: %s", text)
return nil
}
return cl.post(url.Values{
"action": []string{"alert"},
"text": []string{text},