PHP Logging

Published On: 24 June 2016.By .
  • Digital Engineering

Logging is one of the basic requirements of every projects. Logging needs to manage system level errors, data errors for business logic etc. It can be done easily in most of MVC frameworks. Logging can be save in file or in database based on requirements.

image

Core PHP Example
Find the attached logger.php file to use in any core php project or custom project. This provide feature to use logging in files. Example to save logs in files by logger class. You can manage logs based on staging or production environment with some global setting or variable. Follow the below steps to use it.

1. Download the logger class and copy in your project folder.
2. In global config file or bootstrap file, Include the logger class and make a instance.

3. Now you can use logger class function to add log anywhere in your project.

Yii2 Framework Logging ( Advance Template )

Yii2 framework provide inbuilt easy way to manage logging based on files, database and email. Follow the below steps to use it.

1. You need to add below settings in common/config/main.php file.

2. Copy the code.

3. //log table

4. After this setting, you can simply use functions Yii::trace(), Yii::info(), Yii::error() etc. Default logs saved based
on yii2 advance or basic template. Default location is frontend/runtime/logs/app.log

More details can be found here http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html

Download : logger (1)

Related content

That’s all for this blog

Go to Top