mirror of
https://github.com/tobiasehlert/teslamateapi.git
synced 2026-02-27 09:54:18 +08:00
better logg readability
This commit is contained in:
@@ -178,9 +178,9 @@ func TeslaMateAPICars(c *gin.Context) {
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
if CarID > 0 {
|
||||
log.Printf("[TeslaMateAPICars] returned /cars/%d data:", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICars returned /cars/%d data:", CarID)
|
||||
} else {
|
||||
log.Println("[TeslaMateAPICars] returned /cars data:")
|
||||
log.Println("[TeslaMateApi] TeslaMateAPICars returned /cars data:")
|
||||
}
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
@@ -189,16 +189,16 @@ func TeslaMateAPICars(c *gin.Context) {
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
if CarID > 0 {
|
||||
log.Printf("[TeslaMateAPICars] executed /cars/%d successful.", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICars executed /cars/%d successful.", CarID)
|
||||
} else {
|
||||
log.Println("[TeslaMateAPICars] executed /cars successful.")
|
||||
log.Println("[TeslaMateApi] TeslaMateAPICars executed /cars successful.")
|
||||
}
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
if CarID > 0 {
|
||||
log.Printf("[TeslaMateAPICars] error in /cars/%d execution!", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICars error in /cars/%d execution!", CarID)
|
||||
} else {
|
||||
log.Println("[TeslaMateAPICars] error in /cars execution!")
|
||||
log.Println("[TeslaMateApi] TeslaMateAPICars error in /cars execution!")
|
||||
}
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICars.."})
|
||||
}
|
||||
|
||||
@@ -198,17 +198,17 @@ func TeslaMateAPICarsCharges(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Printf("[TeslaMateAPICarsCharges] returned /cars/%d/charges data:", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsCharges returned /cars/%d/charges data:", CarID)
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Printf("[TeslaMateAPICarsCharges] executed /cars/%d/charges successful.", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsCharges executed /cars/%d/charges successful.", CarID)
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Printf("[TeslaMateAPICarsCharges] error in /cars/%d/charges execution!", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsCharges error in /cars/%d/charges execution!", CarID)
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsCharges.."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,17 +318,17 @@ func TeslaMateAPICarsChargesDetails(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Printf("[TeslaMateAPICarsChargesDetails] returned /cars/%d/charges/%d data:", CarID, ChargeID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsChargesDetails returned /cars/%d/charges/%d data:", CarID, ChargeID)
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Printf("[TeslaMateAPICarsChargesDetails] executed /cars/%d/charges/%d successful.", CarID, ChargeID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsChargesDetails executed /cars/%d/charges/%d successful.", CarID, ChargeID)
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Printf("[TeslaMateAPICarsChargesDetails] error in /cars/%d/charges/%d execution!", CarID, ChargeID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsChargesDetails error in /cars/%d/charges/%d execution!", CarID, ChargeID)
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsChargesDetails.."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,17 +246,17 @@ func TeslaMateAPICarsDrives(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Printf("[TeslaMateAPICarsDrives] returned /cars/%d/drives data:", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsDrives returned /cars/%d/drives data:", CarID)
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Printf("[TeslaMateAPICarsDrives] executed /cars/%d/drives successful.", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsDrives executed /cars/%d/drives successful.", CarID)
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Printf("[TeslaMateAPICarsDrives] error in /cars/%d/drives execution!", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsDrives error in /cars/%d/drives execution!", CarID)
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsDrives.."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,17 +381,17 @@ func TeslaMateAPICarsDrivesDetails(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Printf("[TeslaMateAPICarsDrivesDetails] returned /cars/%d/drives/%d data:", CarID, DriveID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsDrivesDetails returned /cars/%d/drives/%d data:", CarID, DriveID)
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Printf("[TeslaMateAPICarsDrivesDetails] executed /cars/%d/drives/%d successful.", CarID, DriveID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsDrivesDetails executed /cars/%d/drives/%d successful.", CarID, DriveID)
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Printf("[TeslaMateAPICarsDrivesDetails] error in /cars/%d/drives/%d execution!", CarID, DriveID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsDrivesDetails error in /cars/%d/drives/%d execution!", CarID, DriveID)
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsDrivesDetails.."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,9 @@ func TeslaMateAPICarsStatus(c *gin.Context) {
|
||||
}
|
||||
|
||||
// showing mqtt successfully connected
|
||||
log.Println("successfully connected to mqtt.")
|
||||
if gin.IsDebugging() {
|
||||
log.Println("[TeslaMateApi] TeslaMateAPICarsStatus successfully connected to mqtt.")
|
||||
}
|
||||
|
||||
// creating structs for /cars
|
||||
// BatteryDetails struct - child of MQTTInformation
|
||||
@@ -586,17 +588,17 @@ func TeslaMateAPICarsStatus(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Printf("[TeslaMateAPICarsStatus] returned /cars/%d/status data:", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsStatus returned /cars/%d/status data:", CarID)
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Printf("[TeslaMateAPICarsStatus] executed /cars/%d/status successful.", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsStatus executed /cars/%d/status successful.", CarID)
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Printf("[TeslaMateAPICarsStatus] error in /cars/%d/status execution!", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsStatus error in /cars/%d/status execution!", CarID)
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsStatus.."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,17 +124,17 @@ func TeslaMateAPICarsUpdates(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Printf("[TeslaMateAPICarsUpdates] returned /cars/%d/updates data:", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsUpdates returned /cars/%d/updates data:", CarID)
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Printf("[TeslaMateAPICarsUpdates] executed /cars/%d/updates successful.", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsUpdates executed /cars/%d/updates successful.", CarID)
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Printf("[TeslaMateAPICarsUpdates] error in /cars/%d/updates execution!", CarID)
|
||||
log.Printf("[TeslaMateApi] TeslaMateAPICarsUpdates error in /cars/%d/updates execution!", CarID)
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsUpdates.."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,17 +127,17 @@ func TeslaMateAPIGlobalsettings(c *gin.Context) {
|
||||
|
||||
// print to log about request
|
||||
if gin.IsDebugging() {
|
||||
log.Println("[TeslaMateAPIGlobalsettings] returned /cars data:")
|
||||
log.Println("[TeslaMateApi] TeslaMateAPIGlobalsettings returned /cars data:")
|
||||
js, _ := json.Marshal(jsonData)
|
||||
log.Printf("%s\n", js)
|
||||
}
|
||||
|
||||
// return jsonData
|
||||
if ValidResponse {
|
||||
log.Println("[TeslaMateAPIGlobalsettings] executed /cars successful.")
|
||||
log.Println("[TeslaMateApi] TeslaMateAPIGlobalsettings executed /cars successful.")
|
||||
c.JSON(http.StatusOK, jsonData)
|
||||
} else {
|
||||
log.Println("[TeslaMateAPIGlobalsettings] error in /cars execution!")
|
||||
log.Println("[TeslaMateApi] TeslaMateAPIGlobalsettings error in /cars execution!")
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPIGlobalsettings.."})
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -114,20 +114,15 @@ func getTimeInTimeZone(datestring string) string {
|
||||
// parsing datestring into TeslaMateDateFormat
|
||||
t, _ := time.Parse(TeslaMateDateFormat, datestring)
|
||||
|
||||
// logging UTC time to log
|
||||
if gin.IsDebugging() {
|
||||
log.Println("[TeslaMateApi] getTimeInTimeZone - UTC: ", t.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
// loading timezone location
|
||||
UserLocation, _ := time.LoadLocation(UsersTimezone)
|
||||
|
||||
// formatting in users location in RFC3339 format
|
||||
ReturnDate := t.In(UserLocation).Format(time.RFC3339)
|
||||
|
||||
// logging Users location-converted time to log
|
||||
// logging time conversion to log
|
||||
if gin.IsDebugging() {
|
||||
log.Println("[TeslaMateApi] getTimeInTimeZone - location at User: " + ReturnDate)
|
||||
log.Println("[TeslaMateApi] getTimeInTimeZone - UTC", t.Format(time.RFC3339), "time converted to", UsersTimezone, "is", ReturnDate)
|
||||
}
|
||||
|
||||
return ReturnDate
|
||||
@@ -185,7 +180,7 @@ func convertStringToBool(data string) bool {
|
||||
return value
|
||||
}
|
||||
// else..
|
||||
log.Println("Error: convertStringToBool could not return value correct.. returning false")
|
||||
log.Println("[TeslaMateApi] convertStringToBool error could not return value correct.. returning false")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -195,7 +190,7 @@ func convertStringToFloat(data string) float64 {
|
||||
return value
|
||||
}
|
||||
// else..
|
||||
log.Println("Error: convertStringToFloat could not return value correct.. returning 0.0")
|
||||
log.Println("[TeslaMateApi] convertStringToFloat error could not return value correct.. returning 0.0")
|
||||
return 0.0
|
||||
}
|
||||
|
||||
@@ -205,7 +200,7 @@ func convertStringToInteger(data string) int {
|
||||
return value
|
||||
}
|
||||
// else..
|
||||
log.Println("Error: convertStringToInteger could not return value correct.. returning 0")
|
||||
log.Println("[TeslaMateApi] convertStringToInteger error could not return value correct.. returning 0")
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user