Commit e2bef985 authored by eileenmcnaughton's avatar eileenmcnaughton Committed by Eileen McNaughton

CRM-14494 add system logger files

CRM-14449 Add system Log table to schema

Conflicts:
	CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl

CRM-14449 add system log

CRM-14449 remove debug
parent 33da127d
......@@ -80,6 +80,7 @@ CRM/Core/DAO/PriceSetEntity.php
CRM/Core/DAO/PrintLabel.php
CRM/Core/DAO/Setting.php
CRM/Core/DAO/StateProvince.php
CRM/Core/DAO/SystemLog.php
CRM/Core/DAO/Tag.php
CRM/Core/DAO/Timezone.php
CRM/Core/DAO/UFField.php
......
......@@ -124,6 +124,23 @@ abstract class CRM_Core_Payment {
return self::$_singleton[$cacheKey];
}
/**
* @param $params
*
* @return mixed
*/
public static function logPaymentNotification($params) {
$message = '';
if (!empty($params['processor_name'])) {
$message = 'processor_name=' . $params['processor_name'];
}
if (!empty($params['processor_id'])) {
$message .= 'processor_id=' . $params['processor_id'];
}
$log = CRM_Utils_SystemLogger();
$log->log('alert', $message, $_REQUEST);
}
/**
* Setter for the payment form that wants to use the processor
*
......@@ -215,6 +232,7 @@ abstract class CRM_Core_Payment {
if (!isset($params['processor_id']) && !isset($params['processor_name'])) {
CRM_Core_Error::fatal("Either 'processor_id' or 'processor_name' param is required for payment callback");
}
self::logPaymentNotification($params);
// Query db for processor ..
$mode = @$params['mode'];
......
......@@ -288,5 +288,24 @@ ALTER TABLE `civicrm_option_group`
UPDATE `civicrm_option_group` SET is_locked = 1 WHERE name IN ('contribution_status','activity_contacts','advanced_search_options','auto_renew_options','contact_autocomplete_options','batch_status','batch_type','batch_mode','contact_edit_options','contact_reference_options','contact_smart_group_display','contact_view_options','financial_item_status','mapping_type','pcp_status','user_dashboard_options','tag_used_for');
-- CRM-14522
ALTER TABLE `civicrm_msg_template` DROP FOREIGN KEY `FK_civicrm_msg_template_pdf_format_id`;
-- CRM-14449
CREATE TABLE `civicrm_system_log` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key: ID.',
`message` VARCHAR(128) NOT NULL COMMENT 'Standardized message',
`context` LONGTEXT NULL COMMENT 'JSON encoded data',
`level` VARCHAR(9) NOT NULL DEFAULT 'info' COMMENT 'error level per PSR3',
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp of when event occurred.',
`contact_id` INT(11) NULL DEFAULT NULL COMMENT 'Optional Contact ID that created the log. Not an FK as we keep this regardless',
hostname VARCHAR(128) NOT NULL COMMENT 'Optional Name of logging host',
PRIMARY KEY (`id`),
INDEX `message` (`message`),
INDEX `contact_id` (`contact_id`),
INDEX `level` (`level`)
)
COMMENT='Table that contains logs of all system events.'
COLLATE='utf8_general_ci';
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
class CRM_Utils_SystemLogger implements \Psr\Log\LoggerInterface {
static public function log($level, $message, array $context = array()) {
echo 'k';
$rec = new CRM_Core_DAO_SystemLog();
$separateFields = array('contact_id', 'hostname');
foreach ($separateFields as $separateField) {
if (isset($context[$separateField])) {
$rec->{$separateField} = $context[$separateField];
unset($context[$separateField]);
}
}
print_r($rec);
$rec->level = $level;
$rec->message = $message;
$rec->context = json_encode($context);
$rec->save();
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
class CRM_Utils_SystemLogger extends Psr\Log\AbstractLogger implements \Psr\Log\LoggerInterface {
public function log($level, $message, array $context = array()) {
$rec = new CRM_Core_DAO_SystemLog();
$separateFields = array('contact_id', 'hostname');
foreach ($separateFields as $separateField) {
if (isset($context[$separateField])) {
$rec->{$separateField} = $context[$separateField];
unset($context[$separateField]);
}
}
$rec->level = $level;
$rec->message = $message;
$rec->context = json_encode($context);
$rec->save();
}
}
......@@ -98,4 +98,61 @@ function civicrm_api3_system_check($params) {
// Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL)
return civicrm_api3_create_success($returnValues, $params, 'System', 'Check');
}
\ No newline at end of file
}
/**
* @param $params
*
* @return array
*/
function civicrm_api3_system_log($params) {
$log = new CRM_Utils_SystemLogger();
// this part means fields with separate db storage are accepted as params which kind of seems more intuitive to me
// because I felt like not doing this required a bunch of explanation in the spec function - but perhaps other won't see it as helpful?
if(!isset($params['context'])) {
$params['context'] = array();
}
$specialFields = array('contact_id', 'hostname');
foreach($specialFields as $specialField) {
if(isset($params[$specialField]) && !isset($params['context'])) {
$params['context'][$specialField] = $params[$specialField];
}
}
$returnValues = $log->log($params['level'], $params['message'], $params['context']);
return civicrm_api3_create_success($returnValues, $params, 'System', 'Log');
}
/**
* Metadata for log function
* @param $params
*/
function _civicrm_api3_system_log_spec($params) {
$params['level'] = array(
'title' => 'Log Level',
'description' => 'Log level as described in PSR3 (info, debug, warning etc)',
'type' => CRM_Utils_Type::T_STRING,
'api.required' => TRUE,
);
$params['message'] = array(
'title' => 'Log Message',
'description' => 'Standardised message string, you can also ',
'type' => CRM_Utils_Type::T_STRING,
'api.required' => TRUE,
);
$params['context'] = array(
'title' => 'Log Context',
'description' => 'An array of additional data to store.',
'type' => CRM_Utils_Type::T_LONGTEXT,
'api.default' => array(),
);
$params['contact_id'] = array(
'title' => 'Log Contact ID',
'description' => 'Optional ID of relevant contact',
'type' => CRM_Utils_Type::T_INT,
);
$params['hostname'] = array(
'title' => 'Log Hostname',
'description' => 'Optional name of host',
'type' => CRM_Utils_Type::T_STRING,
);
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* File for the CiviCRM APIv3 SystemLog functions
*
* @package CiviCRM_APIv3
* @subpackage API_SystemLog
*
* @copyright CiviCRM LLC (c) 2004-2014
* @version $Id: SystemLog.php 30171 2010-10-14 09:11:27Z mover $
*
*/
function civicrm_api3_system_log_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, True, 'SystemLog');
}
......@@ -112,4 +112,14 @@ class api_v3_SystemTest extends CiviUnitTestCase {
$this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH));
}
/**
* Test system log function
*/
function testSystemLog() {
$this->callAPISuccess('system', 'log', array('level' => 'info', 'message' => 'We wish you a merry Christmas'));
$result = $this->callAPISuccess('SystemLog', 'getsingle', array('sequential' => 1, 'message' => array('LIKE' => '%Chris%')));
$this->assertEquals($result['message'], 'We wish you a merry Christmas');
$this->assertEquals($result['level'], 'info');
}
}
<?xml version="1.0" encoding="iso-8859-1" ?>
<table>
<base>CRM/Core</base>
<class>SystemLog</class>
<name>civicrm_system_log</name>
<add>4.5</add>
<field>
<name>id</name>
<type>int unsigned</type>
<title>System Log ID</title>
<required>true</required>
<comment>Primary key ID</comment>
<add>4.4</add>
</field>
<primaryKey>
<name>id</name>
<autoincrement>true</autoincrement>
</primaryKey>
<field>
<name>message</name>
<title>System Log Message</title>
<required>true</required>
<type>varchar</type>
<length>128</length>
<comment>Standardized message</comment>
<add>4.5</add>
</field>
<field>
<name>context</name>
<title>Detailed Log Data</title>
<type>longtext</type>
<comment>JSON encoded data</comment>
<add>4.5</add>
</field>
<field>
<name>level</name>
<title>Detailed Log Data</title>
<comment>error level per PSR3</comment>
<type>varchar</type>
<length>9</length>
<default>info</default>
<add>4.5</add>
</field>
<field>
<name>timestamp</name>
<title>Log Timestamp</title>
<type>timestamp</type>
<comment>Timestamp of when event occurred.</comment>
<default>CURRENT_TIMESTAMP</default>
<add>4.5</add>
</field>
<field>
<name>contact_id</name>
<title>Log Contact ID</title>
<type>int unsigned</type>
<length>11</length>
<comment>Optional Contact ID that created the log. Not an FK as we keep this regardless</comment>
<add>4.5</add>
</field>
<field>
<name>hostname</name>
<title>Log Host</title>
<type>varchar</type>
<length>128</length>
<comment>Optional Name of logging host</comment>
<add>4.5</add>
</field>
</table>
......@@ -35,6 +35,7 @@
<xi:include href="Phone.xml" parse="xml" />
<xi:include href="PreferencesDate.xml" parse="xml" />
<xi:include href="StateProvince.xml" parse="xml" />
<xi:include href="SystemLog.xml" parse="xml" />
<xi:include href="Tag.xml" parse="xml" />
<xi:include href="UFGroup.xml" parse="xml" />
<xi:include href="UFField.xml" parse="xml" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment