remove Config.Logger
This commit is contained in:
parent
310d0052d6
commit
151dc5161f
@ -16,11 +16,6 @@ func (c *Client) RunCallbacks(event *Event) {
|
|||||||
// Log the event.
|
// Log the event.
|
||||||
c.debug.Print("< " + StripRaw(event.String()))
|
c.debug.Print("< " + StripRaw(event.String()))
|
||||||
|
|
||||||
// Log the prettified version of the event.
|
|
||||||
if pretty, ok := event.Pretty(); ok {
|
|
||||||
c.log.Print(StripRaw(pretty))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular wildcard callbacks.
|
// Regular wildcard callbacks.
|
||||||
c.Callbacks.exec(ALLEVENTS, c, event)
|
c.Callbacks.exec(ALLEVENTS, c, event)
|
||||||
|
|
||||||
|
12
client.go
12
client.go
@ -38,8 +38,6 @@ type Client struct {
|
|||||||
tries int
|
tries int
|
||||||
// limiter is a configurable EventLimiter by the end user.
|
// limiter is a configurable EventLimiter by the end user.
|
||||||
limiter *EventLimiter
|
limiter *EventLimiter
|
||||||
// log is used if a writer is supplied for Client.Config.Logger.
|
|
||||||
log *log.Logger
|
|
||||||
// debug is used if a writer is supplied for Client.Config.Debugger.
|
// debug is used if a writer is supplied for Client.Config.Debugger.
|
||||||
debug *log.Logger
|
debug *log.Logger
|
||||||
// quitChan is used to stop the read loop. See Client.Quit().
|
// quitChan is used to stop the read loop. See Client.Quit().
|
||||||
@ -74,9 +72,6 @@ type Config struct {
|
|||||||
// RateLimit is the delay in seconds between events sent to the server,
|
// RateLimit is the delay in seconds between events sent to the server,
|
||||||
// with a burst of 4 messages. Set to -1 to disable.
|
// with a burst of 4 messages. Set to -1 to disable.
|
||||||
RateLimit int
|
RateLimit int
|
||||||
// Logger is an optional, user supplied location to write prettified log
|
|
||||||
// lines to. Defaults to ioutil.Discard.
|
|
||||||
Logger io.Writer
|
|
||||||
// Debugger is an optional, user supplied location to log the raw lines
|
// Debugger is an optional, user supplied location to log the raw lines
|
||||||
// sent from the server, or other useful debug logs. Defaults to
|
// sent from the server, or other useful debug logs. Defaults to
|
||||||
// ioutil.Discard.
|
// ioutil.Discard.
|
||||||
@ -138,13 +133,9 @@ func New(config Config) *Client {
|
|||||||
initTime: time.Now(),
|
initTime: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.Config.Logger == nil {
|
|
||||||
client.Config.Logger = ioutil.Discard
|
|
||||||
}
|
|
||||||
if client.Config.Debugger == nil {
|
if client.Config.Debugger == nil {
|
||||||
client.Config.Debugger = ioutil.Discard
|
client.Config.Debugger = ioutil.Discard
|
||||||
}
|
}
|
||||||
client.log = log.New(client.Config.Logger, "", log.Ltime)
|
|
||||||
client.debug = log.New(client.Config.Debugger, "debug:", log.Ltime|log.Lshortfile)
|
client.debug = log.New(client.Config.Debugger, "debug:", log.Ltime|log.Lshortfile)
|
||||||
|
|
||||||
// Setup a rate limiter if they requested one.
|
// Setup a rate limiter if they requested one.
|
||||||
@ -219,7 +210,6 @@ func (c *Client) Connect() error {
|
|||||||
// Reset the state.
|
// Reset the state.
|
||||||
c.state = newState()
|
c.state = newState()
|
||||||
|
|
||||||
c.log.Printf("[-] connecting to %s...", c.Server())
|
|
||||||
c.debug.Printf("connecting to %s...", c.Server())
|
c.debug.Printf("connecting to %s...", c.Server())
|
||||||
|
|
||||||
// Allow the user to specify their own net.Conn.
|
// Allow the user to specify their own net.Conn.
|
||||||
@ -316,13 +306,11 @@ func (c *Client) Reconnect() (err error) {
|
|||||||
|
|
||||||
// Delay so we're not slaughtering the server with a bunch of
|
// Delay so we're not slaughtering the server with a bunch of
|
||||||
// connections.
|
// connections.
|
||||||
c.log.Printf("[-] reconnecting to %s in %s", c.Server(), c.Config.ReconnectDelay)
|
|
||||||
c.debug.Printf("reconnecting to %s in %s", c.Server(), c.Config.ReconnectDelay)
|
c.debug.Printf("reconnecting to %s in %s", c.Server(), c.Config.ReconnectDelay)
|
||||||
time.Sleep(c.Config.ReconnectDelay)
|
time.Sleep(c.Config.ReconnectDelay)
|
||||||
|
|
||||||
for err = c.Connect(); err != nil && c.tries < c.Config.MaxRetries; c.tries++ {
|
for err = c.Connect(); err != nil && c.tries < c.Config.MaxRetries; c.tries++ {
|
||||||
c.state.reconnecting = true
|
c.state.reconnecting = true
|
||||||
c.log.Printf("[-] reconnecting to %s in %s (%d tries)", c.Server(), c.Config.ReconnectDelay, c.tries)
|
|
||||||
c.debug.Printf("reconnecting to %s in %s (%d tries)", c.Server(), c.Config.ReconnectDelay, c.tries)
|
c.debug.Printf("reconnecting to %s in %s (%d tries)", c.Server(), c.Config.ReconnectDelay, c.tries)
|
||||||
time.Sleep(c.Config.ReconnectDelay)
|
time.Sleep(c.Config.ReconnectDelay)
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,11 @@ import (
|
|||||||
// "hello" with "hello world!".
|
// "hello" with "hello world!".
|
||||||
func Example() {
|
func Example() {
|
||||||
conf := girc.Config{
|
conf := girc.Config{
|
||||||
Server: "irc.byteirc.org",
|
Server: "irc.byteirc.org",
|
||||||
Port: 6667,
|
Port: 6667,
|
||||||
Nick: "test",
|
Nick: "test",
|
||||||
User: "user",
|
User: "user",
|
||||||
Name: "Example bot",
|
Name: "Example bot",
|
||||||
MaxRetries: 3,
|
|
||||||
Logger: os.Stdout,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client := girc.New(conf)
|
client := girc.New(conf)
|
||||||
@ -50,13 +48,11 @@ func Example() {
|
|||||||
// responses to things. E.g. "!hello", "!stop", and "!restart".
|
// responses to things. E.g. "!hello", "!stop", and "!restart".
|
||||||
func Example_commands() {
|
func Example_commands() {
|
||||||
conf := girc.Config{
|
conf := girc.Config{
|
||||||
Server: "irc.byteirc.org",
|
Server: "irc.byteirc.org",
|
||||||
Port: 6667,
|
Port: 6667,
|
||||||
Nick: "test",
|
Nick: "test",
|
||||||
User: "user",
|
User: "user",
|
||||||
Name: "Example bot",
|
Name: "Example bot",
|
||||||
MaxRetries: 3,
|
|
||||||
Logger: os.Stdout,
|
|
||||||
}
|
}
|
||||||
channels := []string{"#dev"}
|
channels := []string{"#dev"}
|
||||||
|
|
||||||
@ -95,13 +91,11 @@ func Example_commands() {
|
|||||||
// one can enter raw IRC commands, which will then be sent to the server.
|
// one can enter raw IRC commands, which will then be sent to the server.
|
||||||
func Example_prompt() {
|
func Example_prompt() {
|
||||||
conf := girc.Config{
|
conf := girc.Config{
|
||||||
Server: "irc.byteirc.org",
|
Server: "irc.byteirc.org",
|
||||||
Port: 6667,
|
Port: 6667,
|
||||||
Nick: "test",
|
Nick: "test",
|
||||||
User: "user",
|
User: "user",
|
||||||
Name: "Example bot",
|
Name: "Example bot",
|
||||||
MaxRetries: 3,
|
|
||||||
Logger: os.Stdout,
|
|
||||||
}
|
}
|
||||||
channels := []string{"#dev"}
|
channels := []string{"#dev"}
|
||||||
|
|
||||||
@ -139,11 +133,11 @@ func Example_prompt() {
|
|||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
client.Callbacks.Add(girc.ALLEVENTS, func(c *girc.Client, e girc.Event) {
|
client.Callbacks.Add(girc.ALLEVENTS, func(c *girc.Client, e girc.Event) {
|
||||||
fmt.Print("\r>> ")
|
fmt.Print("\r> ")
|
||||||
})
|
})
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Print("\r>> ")
|
fmt.Print("\r> ")
|
||||||
input, _ := reader.ReadString('\n')
|
input, _ := reader.ReadString('\n')
|
||||||
input = strings.TrimSpace(input)
|
input = strings.TrimSpace(input)
|
||||||
if len(input) == 0 {
|
if len(input) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user