From 04ea54f1916dea3e373f0fe047a6e726b1b494ab Mon Sep 17 00:00:00 2001 From: Frank Braun Date: Thu, 19 Apr 2018 21:38:23 +0000 Subject: [PATCH] introduce DebugWriter This allows to use a different writer than os.Stderr to write debugging output to. --- xmpp.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xmpp.go b/xmpp.go index 9ddbf42..d10623f 100644 --- a/xmpp.go +++ b/xmpp.go @@ -45,6 +45,9 @@ const ( // Default TLS configuration options var DefaultConfig tls.Config +// DebugWriter is the writer used to write debugging output to. +var DebugWriter io.Writer = os.Stderr + // Cookie is a unique XMPP session identifier type Cookie uint64 @@ -524,7 +527,7 @@ func (c *Client) startTLSIfRequired(f *streamFeatures, o *Options, domain string // will be returned. func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error) { if o.Debug { - c.p = xml.NewDecoder(tee{c.conn, os.Stderr}) + c.p = xml.NewDecoder(tee{c.conn, DebugWriter}) } else { c.p = xml.NewDecoder(c.conn) } @@ -657,7 +660,7 @@ func (c *Client) Send(chat Chat) (n int, err error) { if chat.Thread != `` { thdtext = `` + xmlEscape(chat.Thread) + `` } - return fmt.Fprintf(c.conn, "" + subtext + "%s" + thdtext + "", + return fmt.Fprintf(c.conn, ""+subtext+"%s"+thdtext+"", xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text)) }