Projects STRLCPY prox5 Commits 9c9a42f7
🤬
  • ■ ■ ■ ■ ■
    debug.go
    skipped 37 lines
    38 38  type basicPrinter struct{}
    39 39   
    40 40  func (b *basicPrinter) Print(str string) {
    41  - println("[prox5] " + str)
     41 + if !useDebugChannel {
     42 + println("[prox5] " + str)
     43 + } else {
     44 + debugChan <- str
     45 + }
    42 46  }
    43 47   
    44 48  func (b *basicPrinter) Printf(format string, items ...any) {
    45  - println(fmt.Sprintf("prox5: "+format, items))
     49 + str := fmt.Sprintf("[prox5] "+format, items)
     50 + if !useDebugChannel {
     51 + println(str)
     52 + } else {
     53 + debugChan <- str
     54 + }
    46 55  }
    47 56   
    48 57  // DebugEnabled returns the current state of our debug switch.
    skipped 109 lines
    158 167   return
    159 168   }
    160 169   buf := pools.CopABuffer.Get().(*strings.Builder)
    161  - if success {
    162  - buf.WriteString("verified ")
     170 + if !success {
     171 + buf.WriteString("failed to verify: ")
    163 172   buf.WriteString(sock.Endpoint)
    164  - buf.WriteString(" as ")
    165  - buf.WriteString(sock.protocol.Get().String())
    166  - buf.WriteString(" proxy")
    167 173   p5.dbgPrint(buf)
    168 174   return
    169 175   }
    170  - buf.WriteString("failed to verify: ")
     176 + buf.WriteString("verified ")
    171 177   buf.WriteString(sock.Endpoint)
     178 + buf.WriteString(" as ")
     179 + buf.WriteString(sock.protocol.Get().String())
     180 + buf.WriteString(" proxy")
    172 181   p5.dbgPrint(buf)
    173 182  }
    174 183   
    skipped 7 lines
    182 191   p5.dbgPrint(buf)
    183 192  }
    184 193   
     194 +// ------------
     195 + 
     196 +var (
     197 + debugChan chan string
     198 + useDebugChannel bool
     199 +)
     200 + 
     201 +// DebugChannel will return a channel which will receive debug messages once debug is enabled.
     202 +// This will alter the flow of debug messages, they will no longer print to console, they will be pushed into this channel.
     203 +// Make sure you pull from the channel eventually to avoid build up of blocked goroutines.
     204 +//
     205 +// Deprecated: use DebugLogger instead. This will be removed in a future version.
     206 +func (p5 *Swamp) DebugChannel() chan string {
     207 + debugChan = make(chan string, 100)
     208 + useDebugChannel = true
     209 + return debugChan
     210 +}
     211 + 
Please wait...
Page is in error, reload to recover