dry-logger icon indicating copy to clipboard operation
dry-logger copied to clipboard

accept log messages via block

Open komidore64 opened this issue 1 year ago • 3 comments

fixes #25


This patch allows a Dry-Logger instance to accept log messages via a block.

If a block is passed to #unknown, #debug, #info, #warn, #error, or #fatal, the block's return value becomes the logged message much like the Ruby standardlib Logger.

l = Dry.Logger(:testymctestface, template: :details)
# => #<Dry::Logger::Dispatcher ...

l.info('regular positional argument message')
# [testymctestface] [INFO] [2024-05-01 07:35:36 -0400] regular positional argument message
# => true

l.info { 'a block message' }
# [testymctestface] [INFO] [2024-05-01 07:35:50 -0400] a block message
# => true

l.info('sub-component') { 'fancy-pants block message' }
# [sub-component] [INFO] [2024-05-01 07:36:09 -0400] fancy-pants block message
# => true

I added two spec tests to ensure that block passing works, but I wasn't able to quickly figure out how to check the value of progname.


Thank you for considering my patch!

komidore64 avatar May 01 '24 11:05 komidore64

@timriley this is ready for your eyes!

komidore64 avatar May 01 '24 23:05 komidore64

@komidore64 This is fantastic, thank you!

I've just pushed up some expanded (and passing) tests for the progname handling. Does that behaviour match your expectations?

If you're happy with that, then I can get this in and cut a new release.

timriley avatar May 02 '24 12:05 timriley

@komidore64 This is fantastic, thank you!

I've just pushed up some expanded (and passing) tests for the progname handling. Does that behaviour match your expectations?

I appreciate the assistance. It does! It didn't occur to me that passing progname as a kwarg would also work. I'm glad dry-logger users will have plenty of options.

If you're happy with that, then I can get this in and cut a new release.

I am happy with this. That'd be great!

Thank you for the quick turnaround.

komidore64 avatar May 02 '24 13:05 komidore64

@timriley do you need anything else from me to move this forward? I'm happy to help however I can.

komidore64 avatar May 08 '24 15:05 komidore64

@komidore64 Thank you for checking in! I've just got this ready now (had to sort out a few test failures on the main branch first). I'm going to merge this now and then cut a release. Thanks again!

timriley avatar May 10 '24 02:05 timriley

This is released as v1.0.4. Thanks again @komidore64!

timriley avatar May 10 '24 03:05 timriley