hobbes3
hobbes3

Reputation: 30218

Is it better to use Django's (Python's) built-in logging or try to create custom log messages to a database?

I used to intern at a company that wrote SaaS asset management applications using AJAX and PHP. They wrote their own custom log messages and stored it in the database table to log most actions made by the user or the application.

Now that I have been learning Django, I noticed that the Django documentation says it uses Python's own logging module for logs, which writes to a file.

So for best practice in the Django world, is it better to use Python's logging and write to a file or create a custom model to write logs to a table?

By the way, I'm trying to create like a service request (work orders) app using Django.

Upvotes: 1

Views: 417

Answers (3)

diegueus9
diegueus9

Reputation: 31532

Maybe you need to look at sentry and raven

Upvotes: 1

James Aylett
James Aylett

Reputation: 3372

Python's logging module isn't restricted to outputting to a file. Using handlers, you can control where things go. For instance, I have a logging handler that puts log messages into redis, which I use for some loggers (others can be sent to a file, or syslog, or via another custom handler could go into a relational database as you describe).

I would generally recommend using logging for your logging needs, and choosing your handlers wisely.

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798606

It would be best to create a child of logging.Handler that writes log entries to a table, and let the sysadmin decide whether or not to use it.

Upvotes: 1

Related Questions