What is the business problem that requirement is trying to solve? If you change the logging level AFTER the error, you've already missed the bit you likely want to log. Also, do you intend a mechanism to turn it off? Generally speaking, if you are going to be collecting that sort of information in production (I assume your code will ultimately end up there) you are better off with a person monitoring it so you can turn it on/off without flooding your logs. But again, this comes back to why you are doing this and what you hope to learn. Are you getting that message but the user named doesn't believe they hold the lock? How did they give it back/close the item? Are you using optimistic locking (sounds like no)? I get the sense you're trying to over-engineer a problem and to answer your original question, I don't know how you'd do that programmatically. I'd look at how the system does it. Hopefully it's something you can capture in tracer, although I wouldn't be surprised if at the end of the day a Java API was called.