romana / rlog

A simple Golang logger without external dependencies
Apache License 2.0
39 stars 13 forks source link

enhancement: allow setting "logger name" a-la-Python #24

Open marcelloromani opened 4 years ago

marcelloromani commented 4 years ago

In Python I can do something like

logger = logging.getLogger("foobar")

and foobar gets printed in every line logged by that object.

One use case where this is useful is in Lambdas: by initializing the logger with the lambda name, one can easily filter / see which lambda function emitted the line when using a log aggregation tool, such as CloudWatch or ElasticSearch.

I haven't found a way of obtaining the same with rlog.

Happy to contribute with a PR if needs be.

marcelloromani commented 4 years ago

As (maybe not particularly elegant) workaround, I found the time format can be used:

Setting RLOG_TIME_FORMAT to 2006-01-02 15:04:05.000 $lambda_name does the trick.