mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
review fixes for raw i/o notification
This commit is contained in:
parent
aff1752d67
commit
456174ed53
@ -57,7 +57,7 @@ type Manager struct {
|
|||||||
loggers []singleLogger
|
loggers []singleLogger
|
||||||
stdoutWriteLock sync.Mutex // use one lock for both stdout and stderr
|
stdoutWriteLock sync.Mutex // use one lock for both stdout and stderr
|
||||||
fileWriteLock sync.Mutex
|
fileWriteLock sync.Mutex
|
||||||
dumpingRawInOut bool
|
loggingRawIO bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config represents the configuration of a single logger.
|
// Config represents the configuration of a single logger.
|
||||||
@ -94,7 +94,7 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.loggers = nil
|
logger.loggers = nil
|
||||||
logger.dumpingRawInOut = false
|
logger.loggingRawIO = false
|
||||||
|
|
||||||
// for safety, this deep-copies all mutable data in `config`
|
// for safety, this deep-copies all mutable data in `config`
|
||||||
// XXX let's keep it that way
|
// XXX let's keep it that way
|
||||||
@ -123,7 +123,7 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
|||||||
fileWriteLock: &logger.fileWriteLock,
|
fileWriteLock: &logger.fileWriteLock,
|
||||||
}
|
}
|
||||||
if typeMap["userinput"] || typeMap["useroutput"] || (typeMap["*"] && !(excludedTypeMap["userinput"] && excludedTypeMap["useroutput"])) {
|
if typeMap["userinput"] || typeMap["useroutput"] || (typeMap["*"] && !(excludedTypeMap["userinput"] && excludedTypeMap["useroutput"])) {
|
||||||
logger.dumpingRawInOut = true
|
logger.loggingRawIO = true
|
||||||
}
|
}
|
||||||
if sLogger.MethodFile.Enabled {
|
if sLogger.MethodFile.Enabled {
|
||||||
file, err := os.OpenFile(sLogger.MethodFile.Filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
file, err := os.OpenFile(sLogger.MethodFile.Filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
||||||
@ -140,10 +140,10 @@ func (logger *Manager) ApplyConfig(config []LoggingConfig) error {
|
|||||||
return lastErr
|
return lastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *Manager) DumpingRawInOut() bool {
|
func (logger *Manager) IsLoggingRawIO() bool {
|
||||||
logger.configMutex.RLock()
|
logger.configMutex.RLock()
|
||||||
defer logger.configMutex.RUnlock()
|
defer logger.configMutex.RUnlock()
|
||||||
return logger.dumpingRawInOut
|
return logger.loggingRawIO
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log logs the given message with the given details.
|
// Log logs the given message with the given details.
|
||||||
|
@ -38,7 +38,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rawOutputNotice = "This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect."
|
rawIONotice = "This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect."
|
||||||
)
|
)
|
||||||
|
|
||||||
// Limits holds the maximum limits for various things such as topic lengths.
|
// Limits holds the maximum limits for various things such as topic lengths.
|
||||||
@ -90,6 +90,7 @@ type Server struct {
|
|||||||
ctime time.Time
|
ctime time.Time
|
||||||
defaultChannelModes Modes
|
defaultChannelModes Modes
|
||||||
dlines *DLineManager
|
dlines *DLineManager
|
||||||
|
loggingRawIO bool
|
||||||
isupport *ISupportList
|
isupport *ISupportList
|
||||||
klines *KLineManager
|
klines *KLineManager
|
||||||
limits Limits
|
limits Limits
|
||||||
@ -429,8 +430,8 @@ func (server *Server) tryRegister(c *Client) {
|
|||||||
c.RplISupport()
|
c.RplISupport()
|
||||||
server.MOTD(c)
|
server.MOTD(c)
|
||||||
c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nick, c.ModeString())
|
c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nick, c.ModeString())
|
||||||
if server.logger.DumpingRawInOut() {
|
if server.logger.IsLoggingRawIO() {
|
||||||
c.Notice(rawOutputNotice)
|
c.Notice(rawIONotice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1426,7 +1427,10 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dumpingRawInOut := server.logger.DumpingRawInOut()
|
nowLoggingRawIO := server.logger.IsLoggingRawIO()
|
||||||
|
// notify clients if raw i/o logging was enabled by a rehash
|
||||||
|
sendRawOutputNotice := !initial && !server.loggingRawIO && nowLoggingRawIO
|
||||||
|
server.loggingRawIO = nowLoggingRawIO
|
||||||
|
|
||||||
if initial {
|
if initial {
|
||||||
if err := server.loadDatastore(config.Datastore.Path); err != nil {
|
if err := server.loadDatastore(config.Datastore.Path); err != nil {
|
||||||
@ -1445,8 +1449,8 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
|||||||
sClient.Send(nil, server.name, RPL_ISUPPORT, append([]string{sClient.nick}, tokenline...)...)
|
sClient.Send(nil, server.name, RPL_ISUPPORT, append([]string{sClient.nick}, tokenline...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if dumpingRawInOut {
|
if sendRawOutputNotice {
|
||||||
sClient.Notice(rawOutputNotice)
|
sClient.Notice(rawIONotice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
server.clients.ByNickMutex.RUnlock()
|
server.clients.ByNickMutex.RUnlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user