I've been trying to write a macro to write a message to syslog that includes the file name, line number and a severity that can be called from anywhere including from different threads. I've tried several different ways but I always end up with a compiler error. This latest attempt says that Logger does not implement the DerefMut trait. Other attempts say it does not implement the Copy trait either. Is there any workaround for this?
I've tried using Once and Arc and here's some code using lazy_static:
Note to OP: You can edit your original post by clicking on the pencil icon that appears to the author under any post that they authored. Please do so and correct your formatting as a courtesy to future readers of this thread.
Ah... I read that as a backtick between two single quotes. I need to pay more attention but in my defense I'm doing this from a phone. Anyway, fixed now.
The reason you're running into trouble is that the syslog crate requires mutable access to the logger to use it, and gaining mutable access to globals is not possible without unsafe or a locking mechanism such as a mutex.