Php create simple log file


















Related Articles. PHP Example. PHP Basics. PHP Array Based. PHP Function Based. PHP Date Based. PHP String Based. PHP Class Based. Table of Contents. I just made a few changes: 1.

I added a optional property to set a max size for the log file, with a default of 1 Meg:. This will be useful for others. Your suggestion about adding date to the timestamp format is applied to Logging class. Class now looks simpler — thanks! Thank you! This is nice code I was implement in my project. Thanx so much. Hello, first thing first: thanks for the class! Hi, I've come up with a method that sends you a short email everytime someone successfully logs in.

Hope this helps someone out there I also found that it only worked with admin log-in. I have crudely added the function to the signup. Fionnan Newbie Posts: 3 Logged. Nevermind, I worked it out. Go Up Pages 1. User actions. There are standard Formatters that come with the Monolog package which you can check out here and you also have the ability to create your own.

Logging levels are a vital concern to any logging framework. How do they work in Monolog? Instead, the eight RFC levels are available:. What if you have the need for more flexibility, such as sorting or more detailed filtering? In such a case, you should add Processors to the Logger. The following commands will achieve that:. The next step will be to make use of Monolog from within the PHP code. For this purpose, Composer conveniently generated an autoload. As you might guess, Monolog supports different handlers that allow you to route the logs into different mediums.

Now instantiate a new Logger and name it SimpleLogger:. Next, use StreamHandler to make sure the logger stores the logs into your existing server. Since you want it to capture all log entries in this case, specify the lowest severity level, which is DEBUG. So, delete this line:. As you can see, even though you had to do a bit of up-front setup, this process made logging much more concise and simple.

Given that in real applications, you might want to log hundreds of events, this conciseness will become very handy. The beauty of using a standardized way to log messages besides saving you time while writing your code is the ability to filter the output using simple tools such as grep.

Suppose you want to find messages that have INFO as their severity level.



0コメント

  • 1000 / 1000