| 1 | /* |
| 2 | * Copyright (c) 2024 Contributors to the Eclipse Foundation |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v2.0 |
| 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
| 7 | * |
| 8 | * The Eclipse Public License is available at |
| 9 | * https://www.eclipse.org/legal/epl-2.0/ |
| 10 | * and the Eclipse Distribution License is available at |
| 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
| 12 | * |
| 13 | * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| 14 | */ |
| 15 | |
| 16 | package main |
| 17 | |
| 18 | import "fmt" |
| 19 | |
| 20 | // logger implements the paho.Logger interface |
| 21 | type logger struct { |
| 22 | prefix string |
| 23 | } |
| 24 | |
| 25 | // Println is the library provided NOOPLogger's |
| 26 | // implementation of the required interface function() |
| 27 | func (l logger) Println(v ...interface{}) { |
| 28 | fmt.Println(append([]interface{}{l.prefix + ":"}, v...)...) |
| 29 | } |
| 30 | |
| 31 | // Printf is the library provided NOOPLogger's |
| 32 | // implementation of the required interface function(){} |
| 33 | func (l logger) Printf(format string, v ...interface{}) { |
| 34 | if len(format) > 0 && format[len(format)-1] != '\n' { |
| 35 | format = format + "\n" // some log calls in paho do not add \n |
| 36 | } |
| 37 | fmt.Printf(l.prefix+":"+format, v...) |
| 38 | } |