asenchi / scrolls

Simple logging
MIT License
158 stars 26 forks source link

Feature to add dynamically new data into the global context #33

Closed slemiere closed 11 years ago

slemiere commented 11 years ago

Hello,

I needed for my use case to add dynamically data to the global context so I did something like this:

Scrolls.global_context(Scrolls.global_context.merge(process_name: @process_name))

But it wasn't thread safe and I felt like it could be a pretty common use case so I added the functionality directly into Scrolls with the methods add_global_context, let me know if you think it could be useful and if I should change it.

Thanks !

asenchi commented 11 years ago

Actually, global_context is stored as an atomic object, so I'm pretty sure it should be thread safe. My initial impression is that an add_global_context would be useful, however, I don't think we need the lock you have here. Look in set_global_context for how the atomic object is used.

Like the idea though.

slemiere commented 11 years ago

It is indeed a lot better using the #update method of Atomic, I have updated my pull request accordingly. Let me know what you think.