Browse Source

shorten type names to 10 chars

tags/v2.1.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
f4f7a8afaa
6 changed files with 27 additions and 12 deletions
  1. 1
    1
      conventional.yaml
  2. 2
    2
      irc/client.go
  3. 1
    1
      irc/gateways.go
  4. 18
    3
      irc/logger/logger.go
  5. 4
    4
      irc/server.go
  6. 1
    1
      oragono.yaml

+ 1
- 1
conventional.yaml View File

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

+ 2
- 2
irc/client.go View File

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

+ 1
- 1
irc/gateways.go View File

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

+ 18
- 3
irc/logger/logger.go View File

@@ -46,8 +46,23 @@ var (
46 46
 		LogWarning: "warn",
47 47
 		LogError:   "error",
48 48
 	}
49
+
50
+	// these are old names for log types that might still appear in yaml configs,
51
+	// but have been replaced in the code. this is used for canonicalization when
52
+	// loading configs, but not during logging.
53
+	typeAliases = map[string]string{
54
+		"localconnect":    "connect",
55
+		"localconnect-ip": "connect-ip",
56
+	}
49 57
 )
50 58
 
59
+func resolveTypeAlias(typeName string) (result string) {
60
+	if canonicalized, ok := typeAliases[typeName]; ok {
61
+		return canonicalized
62
+	}
63
+	return typeName
64
+}
65
+
51 66
 // Manager is the main interface used to log debug/info/error messages.
52 67
 type Manager struct {
53 68
 	configMutex     sync.RWMutex
@@ -100,11 +115,11 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
100 115
 	for _, logConfig := range config {
101 116
 		typeMap := make(map[string]bool)
102 117
 		for _, name := range logConfig.Types {
103
-			typeMap[name] = true
118
+			typeMap[resolveTypeAlias(name)] = true
104 119
 		}
105 120
 		excludedTypeMap := make(map[string]bool)
106 121
 		for _, name := range logConfig.ExcludedTypes {
107
-			excludedTypeMap[name] = true
122
+			excludedTypeMap[resolveTypeAlias(name)] = true
108 123
 		}
109 124
 
110 125
 		sLogger := singleLogger{
@@ -227,7 +242,7 @@ func (logger *singleLogger) Log(level Level, logType string, messageParts ...str
227 242
 	// assemble full line
228 243
 
229 244
 	var rawBuf bytes.Buffer
230
-	// XXX magic number here: 9 is len("listeners"), the longest log category name
245
+	// XXX magic number here: 10 is len("connect-ip"), the longest log category name
231 246
 	// in current use. it's not a big deal if this number gets out of date.
232 247
 	fmt.Fprintf(&rawBuf, "%s : %-5s : %-10s : ", time.Now().UTC().Format("2006-01-02T15:04:05.000Z"), LogLevelDisplayNames[level], logType)
233 248
 	for i, p := range messageParts {

+ 4
- 4
irc/server.go View File

@@ -177,7 +177,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
177 177
 	// check DLINEs
178 178
 	isBanned, info := server.dlines.CheckIP(ipaddr)
179 179
 	if isBanned {
180
-		server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected by d-line", ipaddr))
180
+		server.logger.Info("connect-ip", fmt.Sprintf("Client from %v rejected by d-line", ipaddr))
181 181
 		return true, info.BanMessage("You are banned from this server (%s)")
182 182
 	}
183 183
 
@@ -185,7 +185,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
185 185
 	err := server.connectionLimiter.AddClient(ipaddr)
186 186
 	if err == connection_limits.ErrLimitExceeded {
187 187
 		// too many connections from one client, tell the client and close the connection
188
-		server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr))
188
+		server.logger.Info("connect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr))
189 189
 		return true, "Too many clients from your network"
190 190
 	} else if err == connection_limits.ErrThrottleExceeded {
191 191
 		duration := server.Config().Server.IPLimits.BanDuration
@@ -199,7 +199,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
199 199
 
200 200
 		// 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
201 201
 		server.logger.Info(
202
-			"localconnect-ip",
202
+			"connect-ip",
203 203
 			fmt.Sprintf("Client from %v exceeded connection throttle, d-lining for %v", ipaddr, duration))
204 204
 		return true, throttleMessage
205 205
 	} else if err != nil {
@@ -380,7 +380,7 @@ func (server *Server) playRegistrationBurst(session *Session) {
380 380
 	c := session.client
381 381
 	// continue registration
382 382
 	d := c.Details()
383
-	server.logger.Info("localconnect", fmt.Sprintf("Client connected [%s] [u:%s] [r:%s]", d.nick, d.username, d.realname))
383
+	server.logger.Info("connect", fmt.Sprintf("Client connected [%s] [u:%s] [r:%s]", d.nick, d.username, d.realname))
384 384
 	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))
385 385
 
386 386
 	// send welcome text

+ 1
- 1
oragono.yaml View File

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

Loading…
Cancel
Save