jcelliott / lumber

A simple logger for Go
MIT License
63 stars 16 forks source link

Adding Blocking and corresponding checks... #8

Closed sdomino closed 9 years ago

sdomino commented 9 years ago

...to allow for a blocking configuration

Sometimes you may want the logger to block and guarantee a write to your file rather than background it (for instance in a CLI once you've run a command the program may exit before the logger has a chance to write logs).

Now you would be able to set lumber.Blocking = true to achieve that.

jcelliott commented 9 years ago

Have you looked at the Close method? It blocks until all messages have finished writing. This is different from your solution here, but it would work for the example of a CLI program you gave.

sdomino commented 9 years ago

I hadn't seen that, and it does appear to accomplish the same thing.

I only see two minor drawbacks; one being that by using that method the logs fill up with - LOG Closing log now, which isn't a huge issue. The only other potential drawback is that each time you want to os.Exit() you'd need to call log.Close() also, which could be solved by a wrapper anywhere you want to do that.

Anyway, thanks for pointing that out. I'll go ahead and use that as it does exactly what I need, and I can work around the above mentioned points.

Thanks

jcelliott commented 9 years ago

Glad that will work for you. Feel free to open a PR or issue for anything else.