Low level exception handling

Hello

I have a rails application with multithreading that can raise errors
in different threads and i need to write library for storing this
exceptions into file system (into separated files). What is the best
way to catch such kind of exceptions?
Actually i need to store errors from all levels except controller
level.

Thanks