3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-21 19:39:43 +01:00

shorten type names to 10 chars

This commit is contained in:
Shivaram Lingamneni 2020-04-12 13:58:35 -04:00
parent 11d1d96d71
commit f4f7a8afaa
6 changed files with 27 additions and 12 deletions

View File

@ -606,7 +606,7 @@ logging:
# # example of a file log that avoids logging IP addresses
# method: file
# filename: ircd.log
# type: "* -userinput -useroutput -localconnect -localconnect-ip"
# type: "* -userinput -useroutput -connect-ip"
# level: debug
# debug options

View File

@ -277,7 +277,7 @@ func (server *Server) RunClient(conn clientConn, proxyLine string) {
return
}
server.logger.Info("localconnect-ip", fmt.Sprintf("Client connecting from %v", realIP))
server.logger.Info("connect-ip", fmt.Sprintf("Client connecting from %v", realIP))
now := time.Now().UTC()
config := server.Config()
@ -1263,7 +1263,7 @@ func (client *Client) destroy(session *Session) {
client.server.connectionLimiter.RemoveClient(ip)
source = ip.String()
}
client.server.logger.Info("localconnect-ip", fmt.Sprintf("disconnecting session of %s from %s", details.nick, source))
client.server.logger.Info("connect-ip", fmt.Sprintf("disconnecting session of %s from %s", details.nick, source))
}
// decrement stats if we have no more sessions, even if the client will not be destroyed

View File

@ -80,7 +80,7 @@ func (client *Client) ApplyProxiedIP(session *Session, proxiedIP string, tls boo
client.server.connectionLimiter.RemoveClient(session.realIP)
// given IP is sane! override the client's current IP
client.server.logger.Info("localconnect-ip", "Accepted proxy IP for client", parsedProxiedIP.String())
client.server.logger.Info("connect-ip", "Accepted proxy IP for client", parsedProxiedIP.String())
client.stateMutex.Lock()
defer client.stateMutex.Unlock()

View File

@ -46,8 +46,23 @@ var (
LogWarning: "warn",
LogError: "error",
}
// these are old names for log types that might still appear in yaml configs,
// but have been replaced in the code. this is used for canonicalization when
// loading configs, but not during logging.
typeAliases = map[string]string{
"localconnect": "connect",
"localconnect-ip": "connect-ip",
}
)
func resolveTypeAlias(typeName string) (result string) {
if canonicalized, ok := typeAliases[typeName]; ok {
return canonicalized
}
return typeName
}
// Manager is the main interface used to log debug/info/error messages.
type Manager struct {
configMutex sync.RWMutex
@ -100,11 +115,11 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
for _, logConfig := range config {
typeMap := make(map[string]bool)
for _, name := range logConfig.Types {
typeMap[name] = true
typeMap[resolveTypeAlias(name)] = true
}
excludedTypeMap := make(map[string]bool)
for _, name := range logConfig.ExcludedTypes {
excludedTypeMap[name] = true
excludedTypeMap[resolveTypeAlias(name)] = true
}
sLogger := singleLogger{
@ -227,7 +242,7 @@ func (logger *singleLogger) Log(level Level, logType string, messageParts ...str
// assemble full line
var rawBuf bytes.Buffer
// XXX magic number here: 9 is len("listeners"), the longest log category name
// XXX magic number here: 10 is len("connect-ip"), the longest log category name
// in current use. it's not a big deal if this number gets out of date.
fmt.Fprintf(&rawBuf, "%s : %-5s : %-10s : ", time.Now().UTC().Format("2006-01-02T15:04:05.000Z"), LogLevelDisplayNames[level], logType)
for i, p := range messageParts {

View File

@ -177,7 +177,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
// check DLINEs
isBanned, info := server.dlines.CheckIP(ipaddr)
if isBanned {
server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected by d-line", ipaddr))
server.logger.Info("connect-ip", fmt.Sprintf("Client from %v rejected by d-line", ipaddr))
return true, info.BanMessage("You are banned from this server (%s)")
}
@ -185,7 +185,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
err := server.connectionLimiter.AddClient(ipaddr)
if err == connection_limits.ErrLimitExceeded {
// too many connections from one client, tell the client and close the connection
server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr))
server.logger.Info("connect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr))
return true, "Too many clients from your network"
} else if err == connection_limits.ErrThrottleExceeded {
duration := server.Config().Server.IPLimits.BanDuration
@ -199,7 +199,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
server.logger.Info(
"localconnect-ip",
"connect-ip",
fmt.Sprintf("Client from %v exceeded connection throttle, d-lining for %v", ipaddr, duration))
return true, throttleMessage
} else if err != nil {
@ -380,7 +380,7 @@ func (server *Server) playRegistrationBurst(session *Session) {
c := session.client
// continue registration
d := c.Details()
server.logger.Info("localconnect", fmt.Sprintf("Client connected [%s] [u:%s] [r:%s]", d.nick, d.username, d.realname))
server.logger.Info("connect", fmt.Sprintf("Client connected [%s] [u:%s] [r:%s]", d.nick, d.username, d.realname))
server.snomasks.Send(sno.LocalConnects, fmt.Sprintf("Client connected [%s] [u:%s] [h:%s] [ip:%s] [r:%s]", d.nick, d.username, session.rawHostname, session.IP().String(), d.realname))
// send welcome text

View File

@ -627,7 +627,7 @@ logging:
# # example of a file log that avoids logging IP addresses
# method: file
# filename: ircd.log
# type: "* -userinput -useroutput -localconnect -localconnect-ip"
# type: "* -userinput -useroutput -connect-ip"
# level: debug
# debug options