mirror of
https://github.com/soypat/lneto.git
synced 2026-09-07 15:29:05 +00:00
add noslog build tag and small reference section to README
This commit is contained in:
@@ -290,3 +290,11 @@ The document has moved
|
|||||||
</BODY></HTML>
|
</BODY></HTML>
|
||||||
success
|
success
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
### Build tags
|
||||||
|
|
||||||
|
- `debugheaplog`: All logging calls are enabled and all will print out heap information. Warning: Heavy cost on some TinyGo garbage collectors which do not cache the GC statistics
|
||||||
|
- `noslog`: All slog package logging calls omitted.
|
||||||
|
- `xnetdebug`: Packet capture printing to standard output enabled on `xnet.StackAsync` Ethernet and IP receive and send methods
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func run(ctx context.Context, stack *xnet.StackAsync) error {
|
|||||||
return makeMsgErr("resolving Router MAC", err)
|
return makeMsgErr("resolving Router MAC", err)
|
||||||
}
|
}
|
||||||
stack.SetGatewayHardwareAddr(gateway)
|
stack.SetGatewayHardwareAddr(gateway)
|
||||||
berkstack := stack.StackBlocking(stackBackoff).StackGo(xnet.StackGoConfig{
|
gostack := stack.StackBlocking(stackBackoff).StackGo(xnet.StackGoConfig{
|
||||||
ListenerPoolConfig: xnet.TCPPoolConfig{
|
ListenerPoolConfig: xnet.TCPPoolConfig{
|
||||||
PoolSize: tcpConnPoolSize,
|
PoolSize: tcpConnPoolSize,
|
||||||
QueueSize: tcpPacketQueueSize,
|
QueueSize: tcpPacketQueueSize,
|
||||||
@@ -109,7 +109,7 @@ func run(ctx context.Context, stack *xnet.StackAsync) error {
|
|||||||
laddr := net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4(results.AssignedAddr4), 80))
|
laddr := net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4(results.AssignedAddr4), 80))
|
||||||
// raddr := net.TCPAddr{} // If active (client) connection then set raddr in which case a net.Conn type is returned.
|
// raddr := net.TCPAddr{} // If active (client) connection then set raddr in which case a net.Conn type is returned.
|
||||||
const sockstream = 0x1
|
const sockstream = 0x1
|
||||||
c, err := berkstack.Socket(ctx, "tcp", syscall.AF_INET, sockstream, laddr, nil)
|
c, err := gostack.Socket(ctx, "tcp", syscall.AF_INET, sockstream, laddr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return makeMsgErr("creating AF_INET stream socket", err)
|
return makeMsgErr("creating AF_INET stream socket", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
|
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
|
||||||
return true
|
return logEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func logAttrsAndAllocs(allocmsg string, l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
|
func logAttrsAndAllocs(allocmsg string, l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import (
|
|||||||
const HeapAllocDebugging = false
|
const HeapAllocDebugging = false
|
||||||
|
|
||||||
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
|
func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
|
||||||
return l != nil && l.Handler().Enabled(context.Background(), lvl)
|
return logEnabled && l != nil && l.Handler().Enabled(context.Background(), lvl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogAttrs is a helper function that is used by all package loggers and that
|
// LogAttrs is a helper function that is used by all package loggers and that
|
||||||
// can be switched out with the `debugheaplog` build tag for a non-allocating
|
// can be switched out with the `debugheaplog` build tag for a non-allocating
|
||||||
// logger that prints out when heap allocations occur.
|
// logger that prints out when heap allocations occur.
|
||||||
func LogAttrs(l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
|
func LogAttrs(l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
|
||||||
if l != nil {
|
if logEnabled && l != nil {
|
||||||
l.LogAttrs(context.Background(), level, msg, attrs...)
|
l.LogAttrs(context.Background(), level, msg, attrs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//go:build noslog
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
const logEnabled = false
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//go:build !noslog
|
||||||
|
|
||||||
|
package internal
|
||||||
|
|
||||||
|
const logEnabled = true
|
||||||
Reference in New Issue
Block a user