Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Logging - in Database or Logfile?

Tags:

python

logging

I've been working on a server and I'm starting to implement logging. However, I'm not sure whether I should use the db for logging, or just a plaintext file.

I'm planning on logging some basic information for every request (what type of request, ip address of request, session tracking). For some requests there will be extended information present (details on what type of request was made), and if there are any errors I will log those, too.

On the one hand, putting the logs into the db means I could run queries on the logged data. On the other hand, I'm not sure if this would be putting unnecessary strain on the db. Of course, I could also use both the db and a log file for logging. What are people's thoughts on proper logging?

(If it makes a difference, I'm using mod_python on an Apache server with a MySQL db. So I'd either be using the logging library or just creating some logging tables in the db.)

like image 627
Dan Lew Avatar asked Jun 28 '09 22:06

Dan Lew


People also ask

What is the use of logfile?

A log file is a computer-generated data file that contains information about usage patterns, activities, and operations within an operating system, application, server or another device, and is the primary data source for network observability.

What is server logging?

A server log file is a simple text document that contains all activities of a specific server in a given period of time (e.g.,one day). It is automatically created and maintained by the server, and it can provide you with a detailed insight into how, when, and by whom your website or the application was accessed.

What is database logging?

Database logging provides a way to track specific types of changes to the tables and fields in Finance and Operation apps. Changes that can be tracked include insert, update, delete, and rename key operations.

What are the types of server logs?

Availability Logs: track system performance, uptime, and availability. Resource Logs: provide information about connectivity issues and capacity limits. Threat Logs: contain information about system, file, or application traffic that matches a predefined security profile within a firewall.


1 Answers

First, use a logging library like SLF4J/Logback that allows you to make this decision dynamically. Then you can tweak a configuration file and route some or all of your log messages to each of several different destinations.

Be very careful before logging to your application database, you can easily overwhelm it if you're logging a lot of stuff and volume starts to get high. And if your application is running close to full capacity or in a failure mode, the log messages may be inaccessible and you'll be flying blind. Probably the only messages that should go to your application database are high-level application-oriented events (a type of application data).

It's much better to "log to the file system" (which for a large production environment includes logging to a multicast address read by redundant log aggregation servers).

Log files can be read into special analytics databases where you could use eg, Hadoop to do map/reduce analyses of log data.

like image 170
Jim Ferrans Avatar answered Oct 07 '22 03:10

Jim Ferrans