Skip to main content

LOGGING IN PHP

Simple and easy way for logging in php
First, install Apache log4php.
create a configuration file named config.xml containing:
1.<configuration xmlns="http://logging.apache.org/log4php/">
2.    <appender name="myAppender">
3.        <param name="file" value="myLog.log" />
4.    </appender>
5.    <root>
6.        <level value="WARN" />
7.        <appender_ref ref="myAppender" />
8.    </root>
9.</configuration>
This configuration file does the following:
line 2: Creates an appender named myAppender using appender class LoggerAppenderFile which is used for logging to a file.
line 3: Sets the file parameter, which tells the appender to which file to write.
line 6: Sets the root logger level to WARN. This means that logging requests with the level lower than WARN will not be logged by the root logger.
line 7: Links myAppender to the root logger so that all events recieved by the root logger will be forwarded to myAppender and written into the log file.
How to use in code
// Insert the path where you unpacked log4php
include('log4php/Logger.php');

// Tell log4php to use our configuration file.
Logger::configure('config.xml');

// Fetch a logger, it will inherit settings from the root logger
$log = Logger::getLogger('myLogger');

// Start logging
$log->trace("My first message.");   // Not logged because TRACE < WARN
$log->debug("My second message.");  // Not logged because DEBUG < WARN
$log->info("My third message.");    // Not logged because INFO < WARN
$log->warn("My fourth message.");   // Logged because WARN >= WARN
$log->error("My fifth message.");   // Logged because ERROR >= WARN
$log->fatal("My sixth message.");   // Logged because FATAL >= WARN
All material is taken from
http://logging.apache.org/log4php/quickstart.html

Comments

Popular posts from this blog

PHP DATABASE CONNECTION

//connecting to db $conn = mysql_connect("localhost","peter","abc123"); if (!$conn) { die('Could not connect: ' . mysql_error()); } // some code mysql_close($conn); // closing connection //query db $data=$conn->query("SELECT * FROM myTable "); foreach($data as $row) { print_r($row); }

CUSTOM WHERE CLASS IN SUGARCRM DASHLETS

How to add custom where class in sugar dashlets??? for example if you want to see top opportunities dashlet containing only filtered opportunities on some condition then you can do this as below require_once(‘modules/Opportunities/Dashlets/MyOpportunitiesDashlet/MyOpportunitiesDashlet.php’); class MyOpportunitiesCustomDashlet extends MyOpportunitiesDashlet { function MyOpportunitiesCustomDashlet($id, $def = null) { global $current_user, $app_strings, $dashletData; require(‘modules/Opportunities/Dashlets/MyOpportunitiesDashlet/MyOpportunitiesDashlet.data.php’); parent::MyOpportunitiesDashlet($id, $def); } function process($lvsParams = array()) { $lvsParams = array( ‘custom_select’ => ”, ‘custom_from’ => ”, ‘custom_where’ => ‘ AND opportunities.sales_stage=\’Qualification\”, ‘distinct’ => true ); parent::process($lvsParams); } } these codes are only hints, you should know where these piece of codes should be placed to be working..

AJAX BANNED MODULES

In SugarCRM if you want to ban ajax only for particular modules then go to your config_override.php file and add this code $sugar_config['addAjaxBannedModules'][] = “KReports”; //disable ajaxgui for specific module in config override. Now you have done