3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

logging: Add userinput and output, fix up lots

This commit is contained in:
Daniel Oaks 2017-03-06 22:11:10 +10:00
parent 415a8117ee
commit b328a4fcd3
6 changed files with 25 additions and 6 deletions

View File

@ -17,6 +17,7 @@ New release of Oragono!
* Added `USERHOST` command (thanks @vegax87).
### Changed
* Logging is now much better and useful.
### Removed

View File

@ -264,6 +264,8 @@ func (channel *Channel) Join(client *Client, key string) {
return
}
client.server.logger.Log(LogDebug, "join", fmt.Sprintf("%s joined channel %s", client.nick, channel.name))
for member := range channel.members {
if member.capabilities[ExtendedJoin] {
member.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname)
@ -303,6 +305,8 @@ func (channel *Channel) Part(client *Client, message string) {
member.Send(nil, client.nickMaskString, "PART", channel.name, message)
}
channel.Quit(client)
client.server.logger.Log(LogDebug, "part", fmt.Sprintf("%s left channel %s", client.nick, channel.name))
}
func (channel *Channel) GetTopic(client *Client) {

View File

@ -170,6 +170,8 @@ func (client *Client) run() {
maxlenTags, maxlenRest := client.maxlens()
client.server.logger.Log(LogDebug, "userinput ", client.nick, " ->", line)
msg, err = ircmsg.ParseLineMaxLen(line, maxlenTags, maxlenRest)
if err == ircmsg.ErrorLineIsEmpty {
continue
@ -402,7 +404,7 @@ func (client *Client) AllNickmasks() []string {
// SetNickname sets the very first nickname for the client.
func (client *Client) SetNickname(nickname string) error {
if client.HasNick() {
client.server.logger.Log(LogError, "nick", client.nick, fmt.Sprintf("%s nickname already set, something is wrong with server consistency", client.nickMaskString))
client.server.logger.Log(LogError, "nick", fmt.Sprintf("%s nickname already set, something is wrong with server consistency", client.nickMaskString))
return ErrNickAlreadySet
}
@ -419,6 +421,7 @@ func (client *Client) ChangeNickname(nickname string) error {
origNickMask := client.nickMaskString
err := client.server.clients.Replace(client.nick, nickname, client)
if err == nil {
client.server.logger.Log(LogDebug, "nick", fmt.Sprintf("%s changed nickname to %s", client.nick, nickname))
client.server.whoWas.Append(client)
client.nick = nickname
client.updateNickMask()
@ -443,6 +446,8 @@ func (client *Client) destroy() {
return
}
client.server.logger.Log(LogDebug, "quit", fmt.Sprintf("%s is no longer on the server", client.nick))
// send quit/error message to client if they haven't been sent already
client.Quit("Connection closed")
@ -590,6 +595,8 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
line = line[:len(line)-3] + "\r\n"
}
client.server.logger.Log(LogDebug, "useroutput", client.nick, "<- ", strings.TrimRight(line, "\r\n"))
client.socket.Write(line)
return nil
}

View File

@ -9,6 +9,8 @@ import (
"os"
"time"
"strings"
"github.com/mgutz/ansi"
)
@ -115,7 +117,8 @@ func (logger *SingleLogger) Log(level LogLevel, logType string, messageParts ...
}
// ensure we're capturing this logType
capturing := (logger.Types["*"] || logger.Types[logType]) && !logger.ExcludedTypes["*"] && !logger.ExcludedTypes[logType]
logTypeCleaned := strings.ToLower(strings.TrimSpace(logType))
capturing := (logger.Types["*"] || logger.Types[logTypeCleaned]) && !logger.ExcludedTypes["*"] && !logger.ExcludedTypes[logTypeCleaned]
if !capturing {
return
}

View File

@ -644,6 +644,7 @@ func (server *Server) tryRegister(c *Client) {
}
// continue registration
server.logger.Log(LogDebug, "localconnect", fmt.Sprintf("Client registered [%s]", c.nick))
c.Register()
// send welcome text
@ -657,8 +658,6 @@ func (server *Server) tryRegister(c *Client) {
c.RplISupport()
server.MOTD(c)
c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nick, c.ModeString())
server.logger.Log(LogDebug, "localconnect", fmt.Sprintf("Client registered [%s]", c.nick))
}
// MOTD serves the Message of the Day.

View File

@ -196,10 +196,15 @@ logging:
# password password hashing and comparing
# userinput raw lines sent by users
# useroutput raw lines sent to users
type: "* -userinput -useroutput"
type: "* -userinput -useroutput -localconnect -localconnect-ip"
# one of: debug info warn error
level: warn
level: info
-
# avoid logging IP addresses to file
method: stderr
type: localconnect localconnect-ip
level: debug
# datastore configuration
datastore: