You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
Logging inside functions can be done using the methods LogInfo, LogWarn, LogError, and others.
Although, there is no access to these methods from outside the Function classes.
Structured logs
Logging is also not structured, in many instances it is helpful to have access to additional metadata when debugging code such as module version, class, method, etc.
Decoupled from the LambdaSharp framework
Having a dependency on the framework is not ideal, instead, having access to a single log object or class without worrying on how it was configured would be ideal.
Proposal
One way to do this is by using a logging framework such as Serilog. Lambda sharp could configure the logger, and this can be available from other classes:
Example:
In LambdaSharp the logger could be configured like this:
using Serilog;
using Serilog.Formatting.Json;
// ...
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.Enrich.WithProperty("moduleName", ModuleName)
.Enrich.WithProperty("moduleVersion", ModuleVersion)
.Enrich.WithProperty("functionName", FunctionName)
.Enrich.WithProperty("functionId", FunctionId)
// Other default properties
.WriteTo.Console(outputTemplate: "*** {Level:u4}: ")
.WriteTo.Console(new JsonFormatter())
.CreateLogger();
Then this configuration can be used from any class that uses the Log:
using Serilog;
// ...
Log.Warning("Foo");
Log.Information("Bar");
The log Output of this log configuration will look like this:
Serilog provides a number of layouts and configurations that can be added without a lot of setup, it is also very flexible and extensible.
Considerations
I'm not sure at this point what would be the overhead of using a logging framework would be, but Serilog seems to be quite performant compared to the alternatives (NLog and Log4Net).
Motivation
Access from other classes
Logging inside functions can be done using the methods LogInfo, LogWarn, LogError, and others.
Although, there is no access to these methods from outside the Function classes.
Structured logs
Logging is also not structured, in many instances it is helpful to have access to additional metadata when debugging code such as module version, class, method, etc.
Decoupled from the LambdaSharp framework
Having a dependency on the framework is not ideal, instead, having access to a single log object or class without worrying on how it was configured would be ideal.
Proposal
One way to do this is by using a logging framework such as Serilog. Lambda sharp could configure the logger, and this can be available from other classes:
Example:
In LambdaSharp the logger could be configured like this:
Then this configuration can be used from any class that uses the
Log
:The log Output of this log configuration will look like this:
Serilog provides a number of layouts and configurations that can be added without a lot of setup, it is also very flexible and extensible.
Considerations
I'm not sure at this point what would be the overhead of using a logging framework would be, but Serilog seems to be quite performant compared to the alternatives (NLog and Log4Net).
The text was updated successfully, but these errors were encountered: