-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLOB-1020] [CLOB-1048] Logging Library with Contextual Tags (#872)
* Introduce new library for contextualized logging tags * migrate some files over * spelling * actually use the ctx * fix tests about logging * workflow to push and lint * push a binary * snapshot push * migrate all in clob * small fixes * lint * remove sentinel error in favor of log.ErrorLog * properly expand key val tags * nice comments * fix tests * pr comments * pascalcase * tests * remove build and push * fmt lint * fix another test
- Loading branch information
1 parent
925b3b3
commit db848d2
Showing
23 changed files
with
324 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package log | ||
|
||
const ( | ||
SourceModuleKey = "source_module" | ||
Error = "error" | ||
) | ||
|
||
// Tag keys | ||
// Do not have anything generic in here. For example, `Status` is too vague | ||
// and can be clarified as `OrderStatus` or `DaemonHealthStatus`. | ||
const ( | ||
Module = "module" | ||
TxMode = "tx_mode" | ||
OperationsQueue = "operations_queue" | ||
Callback = "callback" | ||
BlockHeight = "block_height" | ||
Msg = "msg" | ||
ProposerConsAddress = "proposer_cons_address" | ||
Handler = "handler" | ||
Tx = "tx" | ||
OrderHash = "order_hash" | ||
OrderStatus = "order_status" | ||
Subaccount = "subaccount" | ||
PerpetualId = "perpetual_id" | ||
MevMatches = "mev_matches" | ||
StackTrace = "stack_trace" | ||
Proposer = "proposer" | ||
PrunableBlockHeight = "prunable_block_height" | ||
|
||
OrderSizeOptimisticallyFilledFromMatchingQuantums = "order_size_optimistically_filled_from_matching_quantums" | ||
NewLocalValidatorOperationsQueue = "new_local_validator_operations_queue" | ||
LocalValidatorOperationsQueue = "local_validator_operations_queue" | ||
) | ||
|
||
// Tag values | ||
const ( | ||
// Module tag values are prefixed with `x/` | ||
Clob = "x/clob" | ||
|
||
CheckTx = "check_tx" | ||
RecheckTx = "recheck_tx" | ||
DeliverTx = "deliver_tx" | ||
) | ||
|
||
// Special tag values that should be PascalCased (i.e function names) | ||
const ( | ||
AnteHandler = "AnteHandler" | ||
PlaceOrder = "PlaceOrder" | ||
CancelOrder = "CancelOrder" | ||
ProposedOperations = "ProposedOperations" | ||
BeginBlocker = "BeginBlocker" | ||
EndBlocker = "EndBlocker" | ||
PrepareCheckState = "PrepareCheckState" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package log | ||
|
||
import ( | ||
"errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// InfoLog reports msg as an info level log with specified key vals. | ||
// `keyvals` should be even number in length and be of alternating types (string, interface{}). | ||
func InfoLog(ctx sdk.Context, msg string, keyvals ...interface{}) { | ||
ctx.Logger().Info(msg, keyvals...) | ||
} | ||
|
||
// DebugLog reports msg as a debug level log with specified key vals. | ||
// `keyvals` should be even number in length and be of alternating types (string, interface{}). | ||
func DebugLog(ctx sdk.Context, msg string, keyvals ...interface{}) { | ||
ctx.Logger().Debug(msg, keyvals...) | ||
} | ||
|
||
// ErrorLogWithError reports msg as a error log with specified key vals, | ||
// as well as attaching the error object to the log for datadog error tracking. | ||
// `keyvals` should be even number in length and be of alternating types (string, interface{}). | ||
func ErrorLogWithError(ctx sdk.Context, msg string, err error, keyvals ...interface{}) { | ||
ctx.Logger().Error(msg, append(keyvals, Error, err)) | ||
} | ||
|
||
// ErrorLog reports msg as a error log. It constructs an error object on the fly with | ||
// the given message object. | ||
// Please try to define a new error and use `ErrorLogWithError` instead. | ||
// `keyvals` should be even number in length and be of alternating types (string, interface{}). | ||
func ErrorLog(ctx sdk.Context, msg string, keyvals ...interface{}) { | ||
err := errors.New(msg) | ||
ErrorLogWithError(ctx, msg, err, keyvals...) | ||
} | ||
|
||
// AddPersistentTagsToLogger returns a new sdk.Context with a logger that has new persistent | ||
// tags that are added to all logs emitted. | ||
// `keyvals` should be even number in length and be of alternating types (string, interface{}). | ||
func AddPersistentTagsToLogger(ctx sdk.Context, keyvals ...interface{}) sdk.Context { | ||
return ctx.WithLogger(ctx.Logger().With(keyvals...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.