mirror of
https://github.com/callebtc/electronwall.git
synced 2025-12-18 15:44:20 +01:00
json or text
This commit is contained in:
@@ -116,7 +116,11 @@ func (app *App) interceptChannelEvents(ctx context.Context) error {
|
||||
|
||||
res := lnrpc.ChannelAcceptResponse{}
|
||||
if accept {
|
||||
contextLogger.Infof("[channel] ✅ Allow channel %s", channel_info_string)
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("allow")
|
||||
} else {
|
||||
log.Infof("[channel] ✅ Allow channel %s", channel_info_string)
|
||||
}
|
||||
res = lnrpc.ChannelAcceptResponse{Accept: true,
|
||||
PendingChanId: req.PendingChanId,
|
||||
CsvDelay: req.CsvDelay,
|
||||
@@ -127,7 +131,11 @@ func (app *App) interceptChannelEvents(ctx context.Context) error {
|
||||
}
|
||||
|
||||
} else {
|
||||
contextLogger.Infof("[channel] ❌ Deny channel %s", channel_info_string)
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("deny")
|
||||
} else {
|
||||
log.Infof("[channel] ❌ Deny channel %s", channel_info_string)
|
||||
}
|
||||
res = lnrpc.ChannelAcceptResponse{Accept: false,
|
||||
Error: Configuration.ChannelRejectMessage}
|
||||
}
|
||||
@@ -160,14 +168,19 @@ func (app *App) logChannelEvents(ctx context.Context) error {
|
||||
event.GetOpenChannel().Capacity,
|
||||
alias,
|
||||
)
|
||||
contextLogger := log.WithFields(log.Fields{
|
||||
"event": "channel_open",
|
||||
"capacity": event.GetOpenChannel().Capacity,
|
||||
"alias": alias,
|
||||
"pubkey": event.GetOpenChannel().RemotePubkey,
|
||||
"chan_id": ParseChannelID(event.GetOpenChannel().ChanId),
|
||||
})
|
||||
contextLogger.Infof("[channel] Opened channel %s %s", ParseChannelID(event.GetOpenChannel().ChanId), channel_info_string)
|
||||
|
||||
if Configuration.LogJson {
|
||||
contextLogger := log.WithFields(log.Fields{
|
||||
"event": "channel",
|
||||
"capacity": event.GetOpenChannel().Capacity,
|
||||
"alias": alias,
|
||||
"pubkey": event.GetOpenChannel().RemotePubkey,
|
||||
"chan_id": ParseChannelID(event.GetOpenChannel().ChanId),
|
||||
})
|
||||
contextLogger.Infof("open")
|
||||
} else {
|
||||
log.Infof("[channel] Opened channel %s %s", ParseChannelID(event.GetOpenChannel().ChanId), channel_info_string)
|
||||
}
|
||||
}
|
||||
log.Tracef("[channel] Event: %s", event.String())
|
||||
}
|
||||
|
||||
@@ -27,7 +27,10 @@ func welcome() {
|
||||
// setLogger will initialize the log format
|
||||
func setLogger(debug bool, json bool) {
|
||||
if json {
|
||||
log.SetFormatter(&log.JSONFormatter{})
|
||||
customFormatter := new(log.JSONFormatter)
|
||||
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
|
||||
customFormatter.PrettyPrint = true
|
||||
log.SetFormatter(customFormatter)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -111,10 +111,18 @@ func (app *App) interceptHtlcEvents(ctx context.Context) error {
|
||||
})
|
||||
|
||||
if <-decision_chan {
|
||||
contextLogger.Infof("[forward] ✅ Allow HTLC %s", forward_info_string)
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("allow")
|
||||
} else {
|
||||
log.Infof("[forward] ✅ Allow HTLC %s", forward_info_string)
|
||||
}
|
||||
response.Action = routerrpc.ResolveHoldForwardAction_RESUME
|
||||
} else {
|
||||
contextLogger.Infof("[forward] ❌ Deny HTLC %s", forward_info_string)
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("deny")
|
||||
} else {
|
||||
log.Infof("[forward] ❌ Deny HTLC %s", forward_info_string)
|
||||
}
|
||||
response.Action = routerrpc.ResolveHoldForwardAction_FAIL
|
||||
}
|
||||
err = interceptor.Send(response)
|
||||
@@ -205,21 +213,41 @@ func (app *App) logHtlcEvents(ctx context.Context) error {
|
||||
|
||||
switch event.Event.(type) {
|
||||
case *routerrpc.HtlcEvent_SettleEvent:
|
||||
contextLogger.Infof("[forward] ⚡️ HTLC SettleEvent")
|
||||
log.Debugf("[forward] Preimage: %s", hex.EncodeToString(event.GetSettleEvent().Preimage))
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("SettleEvent")
|
||||
contextLogger.Debugf("[forward] Preimage: %s", hex.EncodeToString(event.GetSettleEvent().Preimage))
|
||||
} else {
|
||||
log.Infof("[forward] ⚡️ HTLC SettleEvent")
|
||||
log.Debugf("[forward] Preimage: %s", hex.EncodeToString(event.GetSettleEvent().Preimage))
|
||||
}
|
||||
|
||||
case *routerrpc.HtlcEvent_ForwardFailEvent:
|
||||
contextLogger.Infof("[forward] HTLC ForwardFailEvent")
|
||||
log.Debugf("[forward] Reason: %s", event.GetForwardFailEvent().String())
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("ForwardFailEvent")
|
||||
contextLogger.Debugf("[forward] Reason: %s", event.GetForwardFailEvent())
|
||||
} else {
|
||||
log.Infof("[forward] HTLC ForwardFailEvent")
|
||||
log.Debugf("[forward] Reason: %s", event.GetForwardFailEvent().String())
|
||||
}
|
||||
|
||||
case *routerrpc.HtlcEvent_ForwardEvent:
|
||||
contextLogger.Infof("[forward] HTLC ForwardEvent")
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("ForwardEvent")
|
||||
} else {
|
||||
log.Infof("[forward] HTLC ForwardEvent")
|
||||
}
|
||||
// log.Infof("[forward] HTLC ForwardEvent (chan_id:%s, htlc_id:%d)", ParseChannelID(event.IncomingChannelId), event.IncomingHtlcId)
|
||||
// log.Debugf("[forward] Details: %s", event.GetForwardEvent().String())
|
||||
|
||||
case *routerrpc.HtlcEvent_LinkFailEvent:
|
||||
contextLogger.Infof("[forward] HTLC LinkFailEvent")
|
||||
log.Debugf("[forward] Reason: %s", event.GetLinkFailEvent().FailureString)
|
||||
if Configuration.LogJson {
|
||||
contextLogger.Infof("LinkFailEvent")
|
||||
contextLogger.Debugf("[forward] Reason: %s", event.GetLinkFailEvent().FailureString)
|
||||
} else {
|
||||
log.Infof("[forward] HTLC LinkFailEvent")
|
||||
log.Debugf("[forward] Reason: %s", event.GetLinkFailEvent().FailureString)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user