Karan Mitroo
Karan Mitroo

Reputation: 26

Why are logging libraries used when we can simply write files using code?

I am not able to understand that why do we use a library for logging files when we can simply write out the error or the exception by appending to a file.

Upvotes: 1

Views: 75

Answers (1)

M-Razavi
M-Razavi

Reputation: 3467

Logging is a powerful aid for understanding and debugging program’s run-time behavior. Logs capture and persist the important data and make it available for analysis at any point in time.
Both using Logging framework(library) or simply write out log to a file do the minimum job of logging, but choosing one of them depends on size of your software.
For small size software which doesn't do any important/continuous task you don't need any logging framework. But for bigger one you need one of them without doubt. Some pros of Logging framework:

  • Thread-safe
  • Asynchronous Logging
  • Enable/Disable logs without rebuild codes
  • Set multiple level of log
  • Change level of log without rebuild codes
  • Multiple output method of logs (file, network, syslog,...)
  • Log rotate (manage log files based on size, date,...)

Upvotes: 1

Related Questions