Skip to content

Commit 24d3f79

Browse files
Maurizio Brancapolldo
Maurizio Branca
authored andcommitted
Enable MQTT logging (brutal edition) (#2)
1 parent 2d0e65c commit 24d3f79

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

command/ping.go

+21-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ package command
22

33
import (
44
"fmt"
5-
paho "github.com/eclipse/paho.mqtt.golang"
6-
"github.com/spf13/cobra"
7-
"github.com/zmoog/mariquita/adapters/mqtt"
8-
"github.com/zmoog/mariquita/internal/properties"
5+
"log"
96
"math/rand"
107
"os"
118
"os/signal"
129
"syscall"
1310
"time"
11+
12+
paho "github.com/eclipse/paho.mqtt.golang"
13+
"github.com/spf13/cobra"
14+
"github.com/zmoog/mariquita/adapters/mqtt"
15+
"github.com/zmoog/mariquita/internal/properties"
1416
)
1517

1618
var (
17-
host string
18-
username string
19-
password string
20-
thingID string
19+
host string
20+
username string
21+
password string
22+
thingID string
23+
troubleshooting bool
2124
)
2225

2326
func init() {
@@ -26,6 +29,8 @@ func init() {
2629
pingCommand.Flags().StringVarP(&password, "password", "p", "", "Password (required)")
2730
pingCommand.Flags().StringVarP(&thingID, "thing_id", "t", "", "Thing ID (required)")
2831

32+
pingCommand.Flags().BoolVar(&troubleshooting, "troubleshooting", false, "Enable troubleshooting mode (full logs from the MQTT client)")
33+
2934
pingCommand.MarkFlagRequired("username")
3035
pingCommand.MarkFlagRequired("password")
3136
pingCommand.MarkFlagRequired("thing_id")
@@ -38,6 +43,14 @@ var pingCommand = &cobra.Command{
3843
Short: "Ping Arduino IoT Cloud",
3944
Long: "Ping Arduino IoT Cloud",
4045
RunE: func(cmd *cobra.Command, args []string) error {
46+
47+
if troubleshooting {
48+
paho.ERROR = log.New(os.Stdout, "[ERROR] ", 0)
49+
paho.CRITICAL = log.New(os.Stdout, "[CRIT] ", 0)
50+
paho.WARN = log.New(os.Stdout, "[WARN] ", 0)
51+
paho.DEBUG = log.New(os.Stdout, "[DEBUG] ", 0)
52+
}
53+
4154
mqttAdapter := mqtt.NewAdapterWithAuth(
4255
host,
4356
username,

0 commit comments

Comments
 (0)