0

I'm working on a php project which is processing and modifying data entries on a large scale. Data is taken from database and goes through 7 validation tests. Data is then sorted and inserted to database again. This process is time consuming and difficult to track errors and failures.

I want to create log writer class for my application.

There are basically two options:

  1. writing log in text file
  2. writing log in Database

which method is more efficient or any other options?

2
  • possible duplicate of PHP Logging framework? Commented Jan 25, 2012 at 13:47
  • 1
    I voted for the duplicate, but actually I must admit you don't have posed an actual question. What is more efficient depends on whether your file-system is more efficient than the database or not. Also it depends on what you want to achieve, what kind of logging you need etc., so please improve your question. Commented Jan 26, 2012 at 12:16

3 Answers 3

2

while you could do your own logger I would recommend you log4php which is a well tested library and with the support of the apache fundation

Sign up to request clarification or add additional context in comments.

Comments

1

Writing log into database is efficient only if those logs are used only rarely (for example you need to check error once in time). If you want to sort and filter errors, the database is the way to go.

You could create table like this:

CREATE TABLE `logs` (
  `id` INT AUTO_INCREMENT,
  `original_id` INT NOT NULL, -- will contain FOREIGN KEY
  `new_id` INT DEFAULT NULL, -- will contain FOREIGN KEY
  `validator_id` INT, -- ID of validator which triggered error
  `type` ENUM('error', 'notice') DEFAULT 'error',
  `message` VARCHAR(255) DEFAULT '',
  PRIMARY KEY (`id`)
)

which will allow you to browse your error really easily.

Comments

1

Text files are easier to monitor from the command line in Unix machines:

$ tail -f /path/thefile.log

This gives you a constantly-updating view of the newest lines of a text file. You don't have to do it that way, of course. I think in most cases a text file is sufficient.

Databases are great if you want to do efficient sorting, filtering, and relational operations (ie. you want to relate one log entry to another sort of information that is stored). It takes longer to set this up, so be sure to determine how permanently you need this logging and how robust you need it to be. If it's for simple review, I'd stick with a text file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.