Just a quick update, hereās the function with stacktrace, I wrote it slightly differently to pgrās example, so it only returns part of the stacktrace, for full trace uncomment where it says ā// UNCOMMENT BELOW FOR FULL STACK TRACEā
Include it in your customutils.php file and then you can put it anywhere in your suitecrm code like this
write_to_log($arr), āSome stuff happenedā);
^ $arr can be either an array or an object (it works with both)
and it will write it to custom/log.txt
function write_to_log($arr, $str, $email = true) {
date_default_timezone_set('America/New_York');
$time_stamp = date("Y-m-d h:i:sa");
// If the $arr is an object then convert it into an array first
if(is_object($arr)) {
$arr = serialize($arr);
$arr = unserialize($arr);
$txt = $str.PHP_EOL.PHP_EOL;
$txt.= "<pre>".print_r($arr, true)."</pre>".PHP_EOL.PHP_EOL;
file_put_contents('custom/log.txt', PHP_EOL.PHP_EOL, FILE_APPEND);
file_put_contents('custom/log.txt', $txt, FILE_APPEND);
file_put_contents('custom/log.txt', PHP_EOL.PHP_EOL, FILE_APPEND);
return;
}
if(!empty($arr)) {
// Get readable stacktrace info that will go into the array
$content = unserialize(serialize(debug_backtrace()));
$content = parse_into_string($content);
$arr["Date_time"] = $time_stamp; /* This date goes into the txt file only */
$arr["StackTrace"] = $content;
$txt = $str.":".PHP_EOL;
$txt.= "<pre>".print_r($arr, true)."</pre>".PHP_EOL.PHP_EOL;
} else {
$txt = $str." (".$time_stamp.")".PHP_EOL.PHP_EOL;
}
file_put_contents('custom/log.txt', $txt, FILE_APPEND);
# Now email
if($email == true)
// email_update($txt, $str);
}
// Will take the content of the stack trace and parse it into a more manageable array
function parse_into_string($stackTrace) {
$ignore = array(
"custom_utils.ext.php",
);
$report = "";
foreach ($stackTrace as $s) {
// Skip any system file we wish to ignore
if(isset($s["file"]) AND in_array(basename($s["file"]), $ignore) !== false) {
continue;
}
if(isset($s["class"]))
$report .= "Class: ".$s["class"]." ";
if(isset($s["function"]))
$report .= "Function/method: ".$s["function"]."() ";
if(isset($s["file"]))
$report .= "File: ".basename($s["file"])." ";
if(isset($s["line"]))
$report .= "on line: ".$s["line"]." ";
$report .= " | ";
// UNCOMMENT BELOW FOR FULL STACK TRACE
break;
}
return $report;
}
Sorry I meant ācomment out the lineā to get the full stack trace Otherwise it will break; after first loop.
Youāre right about missing curly bracket for email function. In my production code itās not commented out so it does work, but if you just copy/paste directly it would throw an error.
Let me know if you have any more questions
Btw hereās the missing email function just in case
I was looking through all the material you have on Youtube, which is amazing⦠thanks!
I was wondering if you would be willing to contribute something to the Docs site (docs.suitecrm.com). We have a Technical Blog there which ideally would gather contributions from many different Community members. And some of the things you documented in Video, would be good material to incorporate to the Docs themselves.
My favorite is the āfields in relationshipsā tutorials, we really should have that documented in text somewhereā¦
If you feel motivated for such a thing, even if itās just one or two articles to try it, I could assist you in learning the mark up language and any other issues you might need to learn in order to write in our Docs.