Exemple #1
0
// Proxy returns a ProxyFunc that uses custom function if provided, otherwise falls back to DefaultProxyFuncs.
func Proxy(p ProxyFuncs) ProxyFunc {
	return func(remote net.Conn, msg *proto.ControlMessage) {
		var f ProxyFunc
		switch msg.Protocol {
		case proto.HTTP:
			f = DefaultProxyFuncs.HTTP
			if p.HTTP != nil {
				f = p.HTTP
			}
		case proto.TCP:
			f = DefaultProxyFuncs.TCP
			if p.TCP != nil {
				f = p.TCP
			}
		case proto.WS:
			f = DefaultProxyFuncs.WS
			if p.WS != nil {
				f = p.WS
			}
		}

		if f == nil {
			logging.Error("Could not determine proxy function for %v", msg)
			remote.Close()
		}

		f(remote, msg)
	}
}
Exemple #2
0
func main() {

	// Default logger
	logging.Debug("Debug")
	logging.Info("Info")
	logging.Notice("Notice")
	logging.Warning("Warning")
	logging.Error("Error")
	logging.Critical("Critical")

	// Custom logger with default handler
	l := logging.NewLogger("test")

	l.Debug("Debug")
	l.Info("Info")
	l.Notice("Notice")
	l.Warning("Warning")
	l.Error("Error")
	l.Critical("Critical")

	// Custom logger with custom handler
	l2 := logging.NewLogger("test2")
	l2.SetHandler(&MyHandler{})

	l2.Debug("Debug")
	l2.Info("Info")
	l2.Notice("Notice")
	l2.Warning("Warning")
	l2.Error("Error")
	l2.Critical("Critical")
}