withLogContext() function
Wraps around a callback, automatically creating and managing the lifecycle for a LogContext.
Signature:
export declare function withLogContext<R = void>(config: PartialRLogConfig, callback: ContextCallback<R>): R;
Parameters
Parameter | Type | Description |
---|---|---|
config | Config to create the context with. | |
callback | ContextCallback scope to run and provide the context for. |
Returns:
R
Remarks
The callback will be invoked immediately, and within the same thread.
Any errors thrown within the callback will be re-thrown after calling stop on the created context to avoid memory leaks.
Any value returned from the callback will also be propagated appropriately.
Example
remotes.buyPet.connect((player: Player, pet: PetId) => {
// automatically starts and stops the context
withLogContext({ minLogLevel: LogLevel.DEBUG }, (context) => {
buyPet(context, player.UserId, pet);
});
});