/** * Test that a message can be written to a log file. * * @return \Core\Utilities\Logger\LogFile The log file created. */ public function testWrite(){ $type = 'testphpunit'; $msg = \BaconIpsumGenerator::Make_a_Sentence(); $code = '/test/' . Core::RandomHex(6); // First, I'll test the functional method. \Core\Utilities\Logger\append_to($type, $msg, $code); // Now a file should exist called testphpunit.log that contains the line above. $this->assertTrue(file_exists(ROOT_PDIR . 'logs/' . $type . '.log')); $contents = file_get_contents(ROOT_PDIR . 'logs/' . $type . '.log'); $this->assertContains($msg, $contents); $this->assertContains($code, $contents); // And now the class method, (should be identical). $type = 'testphpunit'; $msg = \BaconIpsumGenerator::Make_a_Sentence(); $code = '/test/' . Core::RandomHex(6); // First, I'll test the functional method. $log = new \Core\Utilities\Logger\LogFile($type); $log->write($msg, $code); // Now a file should exist called testphpunit.log that contains the line above. $this->assertTrue($log->exists()); $contents = $log->getContents(); $this->assertContains($msg, $contents); $this->assertContains($code, $contents); return $log; }
public function save($defer = false){ if(Core::IsComponentAvailable('core')){ $isnew = !$this->exists(); $ret = parent::save($defer); // No change happened, nothing extra to do. if(!$ret){ return $ret; } // Wasn't a previously new model? Also nothing to do beyond. if(!$isnew){ return $ret; } } // @todo email message function // log message (to file). if( ($this->get('type') == 'error' || $this->get('type') == 'security') && $this->get('details') ){ Core\Utilities\Logger\append_to($this->get('type'), $this->get('message') . "\n" . $this->get('details'), $this->get('code')); } else{ Core\Utilities\Logger\append_to($this->get('type'), $this->get('message'), $this->get('code')); } }
public function stopError($code, $error){ if(sizeof($this->_last) == 0){ // Nothing to do, you must use start first! return; } $last = array_pop($this->_last); $time = microtime(true) - $last['start']; $timeFormatted = \Core\time_duration_format($time, 2); if($last['type'] == 'read'){ ++$this->_reads; } else{ ++$this->_writes; } if(DEVELOPMENT_MODE) { // Add this data to the SESSION if the site is currently in DEV mode. $events = Session::Get('datamodel_profiler_events/events', []); $events[] = [ 'query' => $last['query'], 'type' => $last['type'], 'time' => $time, 'errno' => $code, 'error' => $error, 'caller' => $last['caller'], 'rows' => 0 ]; Session::Set('datamodel_profiler_events/events', $events); if($last['type'] == 'read') { Session::Set('datamodel_profiler_events/reads', Session::Get('datamodel_profiler_events/reads') + 1); } else { Session::Set('datamodel_profiler_events/writes', Session::Get('datamodel_profiler_events/writes') + 1); } } if(defined('DMI_QUERY_LOG_TIMEOUT') && DMI_QUERY_LOG_TIMEOUT >= 0){ if(DMI_QUERY_LOG_TIMEOUT == 0 || ($time * 1000) >= DMI_QUERY_LOG_TIMEOUT ){ \Core\Utilities\Logger\append_to('query', '[' . $timeFormatted . '] ' . $last['query'], 0); } } }