Beautify logs with xlog

This commit is contained in:
Andreas Neue
2016-03-12 13:09:25 +01:00
parent 13379b29ea
commit 1dea72f6c7
11 changed files with 60 additions and 48 deletions
+14 -11
View File
@@ -9,11 +9,12 @@ package main
import (
"flag"
"fmt"
"log"
"runtime"
"strings"
"time"
"code.dnix.de/an/xlog"
"github.com/nickvanw/ircx"
"github.com/sorcix/irc"
"github.com/sorcix/irc/ctcp"
@@ -42,13 +43,15 @@ var (
func main() {
sayCh = make(chan string, 1024)
xlog.Init(xlog.INFO)
//bot := ircx.Classic(*server, *name)
cfg := ircx.Config{User: *name, MaxRetries: 1000}
bot := ircx.New(*server, *name, cfg)
log.Printf("%s started", SoftwareInfo())
log.Println("Logging in")
xlog.Info("%s started", SoftwareInfo())
xlog.Info("Logging in")
if err := bot.Connect(); err != nil {
log.Panicln("Unable to dial IRC Server:", err)
xlog.Fatal("Unable to dial IRC Server: %v", err)
}
//mods := strings.Split(*modules, ",")
@@ -81,11 +84,11 @@ func main() {
RegisterHandlers(bot)
bot.HandleLoop()
log.Println("Exiting")
xlog.Info("Exiting")
}
func RegisterHandlers(bot *ircx.Bot) {
log.Println("Registering handlers")
xlog.Info("Registering handlers")
bot.HandleFunc(irc.RPL_WELCOME, ConnectHandler)
bot.HandleFunc(irc.PING, PingHandler)
bot.HandleFunc(irc.PRIVMSG, PrivmsgHandler)
@@ -93,14 +96,14 @@ func RegisterHandlers(bot *ircx.Bot) {
func ConnectHandler(s ircx.Sender, m *irc.Message) {
if *nspass != "" {
log.Printf("Authenticating with NickServ: %v, %v", *name, *nspass)
xlog.Info("Authenticating with NickServ: %v, %v", *name, *nspass)
s.Send(&irc.Message{
Command: irc.PRIVMSG,
Params: []string{*nsname},
Trailing: "IDENTIFY " + *name + " " + *nspass,
})
}
log.Printf("Joining channels: %v", *channels)
xlog.Info("Joining channels: %v", *channels)
for _, ch := range strings.Split(*channels, ",") {
s.Send(&irc.Message{
Command: irc.JOIN,
@@ -108,12 +111,12 @@ func ConnectHandler(s ircx.Sender, m *irc.Message) {
})
}
time.Sleep(2 * time.Second)
msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf("running on %s", SoftwareInfo()))
msg := ctcp.Action(fmt.Sprintf("running on %s", SoftwareInfo()))
sayCh <- fmt.Sprintf("%s\n%s", "*", msg)
}
func PingHandler(s ircx.Sender, m *irc.Message) {
log.Println("PingPong")
xlog.Info("PingPong")
s.Send(&irc.Message{
Command: irc.PONG,
Params: m.Params,
@@ -134,7 +137,7 @@ func HandleMessage(m *irc.Message) {
}
switch tok[0] {
case "!version":
msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf("running on %s", SoftwareInfo()))
msg := ctcp.Action(fmt.Sprintf("running on %s", SoftwareInfo()))
sayCh <- fmt.Sprintf("%s\n%s", "*", msg)
//sayCh <- fmt.Sprintf("%s\n%s", "*", SoftwareInfo())
default: