rename p1
This commit is contained in:
21
renamed/LICENSE
Normal file
21
renamed/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Joey Kimsey
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
58
renamed/README.md
Normal file
58
renamed/README.md
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
# Canary
|
||||
|
||||
Canary is a PHP Library for creating and managing application logs. Originally paired with a browser extension for live logging, the tool now provides a standardized interface for creating managing and saving log messages as files as well as displaying a front-end component for on-page debugging.
|
||||
|
||||
## Installation
|
||||
|
||||
To install simply use the composer command:
|
||||
|
||||
`php composer.phar require thetempusproject/canary`
|
||||
|
||||
## Usage
|
||||
|
||||
Typical usage would be through including the package via composer.
|
||||
|
||||
```php
|
||||
|
||||
require_once VENDOR_DIRECTORY . 'autoload.php';
|
||||
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
|
||||
Debug::info( 'Function called' );
|
||||
Debug::warn( 'This is a warning message' );
|
||||
|
||||
```
|
||||
|
||||
If you would like to use hermes autoloading, simply inclode the constants file and the autoload file inside `/bin/`.
|
||||
|
||||
```php
|
||||
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
|
||||
// Canary Constants
|
||||
if ( ! defined( 'CANARY_CONSTANTS_LOADED' ) ) {
|
||||
if ( defined( 'CANARY_CONFIG_DIRECTORY' ) ) {
|
||||
require_once CANARY_CONFIG_DIRECTORY . 'constants.php';
|
||||
}
|
||||
}
|
||||
|
||||
// Canary Autoloader (Autoloader)
|
||||
if ( ! defined( 'CANARY_AUTOLOADED' ) ) {
|
||||
if ( defined( 'CANARY_ROOT_DIRECTORY' ) ) {
|
||||
require_once CANARY_ROOT_DIRECTORY . 'bin' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
}
|
||||
}
|
||||
|
||||
Debug::info( 'Function called' );
|
||||
Debug::warn( 'This is a warning message' );
|
||||
|
||||
```
|
||||
|
||||
## Issues / Bugs / Contact
|
||||
|
||||
If anyone actually uses this library and runs into any issues, feel free to contact me and I'll look into it.
|
||||
|
||||
[Joey Kimsey](mailto:Joey@thetempusproject.com) - _Lead Developer_
|
||||
|
||||
[JoeyKimsey.com](https://JoeyKimsey.com)
|
43
renamed/bin/autoload.php
Normal file
43
renamed/bin/autoload.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* autoload.php
|
||||
*
|
||||
* Uses the Hermes autoloader if it has been defined.
|
||||
*
|
||||
* @version 1.0.7
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/libraries/Canary
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary;
|
||||
|
||||
use TheTempusProject\Hermes\Classes\Autoloader;
|
||||
|
||||
if ( !defined( 'CANARY_ROOT_DIRECTORY' ) ) {
|
||||
define( 'CANARY_ROOT_DIRECTORY', dirname( __DIR__ ) . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
|
||||
if ( ! defined('CANARY_CONFIG_DIRECTORY' ) ) {
|
||||
define('CANARY_CONFIG_DIRECTORY', CANARY_ROOT_DIRECTORY . 'Config' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if ( ! defined('CANARY_CONSTANTS_LOADED' ) ) {
|
||||
require_once CANARY_CONFIG_DIRECTORY . 'constants.php';
|
||||
}
|
||||
|
||||
if ( class_exists( 'TheTempusProject\Hermes\Classes\Autoloader' ) ) {
|
||||
$Autoloader = new Autoloader;
|
||||
$autoloader->setRootFolder( CANARY_ROOT_DIRECTORY );
|
||||
$autoloader->addNamespace(
|
||||
'TheTempusProject\Canary\Classes',
|
||||
'Classes'
|
||||
);
|
||||
$autoloader->addNamespace(
|
||||
'TheTempusProject\Canary',
|
||||
'Bin'
|
||||
);
|
||||
$Autoloader->register();
|
||||
define( 'CANARY_AUTOLOADED', true );
|
||||
}
|
||||
|
||||
require_once 'Canary.php';
|
454
renamed/bin/canary.php
Normal file
454
renamed/bin/canary.php
Normal file
@ -0,0 +1,454 @@
|
||||
<?php
|
||||
/**
|
||||
* bin/canary.php
|
||||
*
|
||||
* The Canary class is responsible for providing a log of relevant debugging information.
|
||||
* It has functionality to generate a log file as it goes allowing you to print it at any
|
||||
* given point in the script. It can also interface directly with the browser via the
|
||||
* Overwatch browser extension.
|
||||
*
|
||||
* @version 1.0.7
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/libraries/Canary
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary\Bin;
|
||||
|
||||
use TheTempusProject\Canary\Classes\TempusDebugger;
|
||||
use TheTempusProject\Canary\Classes\Logger;
|
||||
use Exception;
|
||||
|
||||
class Canary {
|
||||
|
||||
private static $lastCall = '';
|
||||
private static $group = 0;
|
||||
private static $tempusDebugger;
|
||||
private static $tempusLogger;
|
||||
private static $debugLog = '';
|
||||
|
||||
/**
|
||||
* @param {object} [$exception]
|
||||
*/
|
||||
public static function handle_exception( $exception ) {
|
||||
echo '<div style="margin-top: 80px;margin-bottom: 80px;margin-left: 275px;">';
|
||||
echo '<hr><h3>Exception Handler:</h3>';
|
||||
echo '<b>Class: </b><code>' . get_class( $exception ) . '</code><br>';
|
||||
// echo "<b>Message: </b><code>{ $exception->message }" . '</code><br>';
|
||||
// echo "<b>File: </b><code>{ $exception->getFile() }" . '</code><br>';
|
||||
// echo "<b>Line: </b><code>{ $exception->getLine() }" . '</code><br>';
|
||||
echo '<b>Exception:</b><pre>' . print_r( $exception, true ) . '</pre><br><hr>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} [$exception]
|
||||
*/
|
||||
public static function handle_error( $error_code, $error_description, $file = null, $error_line_number = null ) {
|
||||
$displayErrors = ini_get( 'display_errors' );
|
||||
$displayErrors = strtolower( $displayErrors );
|
||||
echo '<div style="margin-top: 80px;margin-bottom: 80px;margin-left: 275px;">';
|
||||
if ( 0 === $error_code || 0 === error_reporting() || $displayErrors === 'on' ) {
|
||||
echo '<h1>fail</h1></div>';
|
||||
return false;
|
||||
}
|
||||
// wtf? remove this or find an alternative
|
||||
// if ( isset( $GLOBALS['error_fatal'] ) ) {
|
||||
// if ( $GLOBALS['error_fatal'] && $error_code ) {
|
||||
// die('fatal');
|
||||
// }
|
||||
// }
|
||||
|
||||
$errstr = htmlspecialchars( $error_description );
|
||||
switch( $error_code ) {
|
||||
case E_ERROR:
|
||||
$errorType = 'E_ERROR';
|
||||
$errorReadable = 'Fatal Error';
|
||||
// throw new ErrorException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_ERR;
|
||||
break;
|
||||
case E_WARNING:
|
||||
$errorType = 'E_WARNING';
|
||||
$errorReadable = 'Warning';
|
||||
// throw new WarningException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_WARNING;
|
||||
break;
|
||||
case E_PARSE:
|
||||
$errorType = 'E_PARSE';
|
||||
$errorReadable = 'Parse Error';
|
||||
// throw new ParseException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_ERR;
|
||||
break;
|
||||
case E_NOTICE:
|
||||
$errorType = 'E_NOTICE';
|
||||
$errorReadable = 'Notice';
|
||||
// throw new NoticeException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_NOTICE;
|
||||
break;
|
||||
case E_CORE_ERROR:
|
||||
$errorType = 'E_CORE_ERROR';
|
||||
$errorReadable = 'Core Error';
|
||||
// throw new CoreErrorException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_ERR;
|
||||
break;
|
||||
case E_CORE_WARNING:
|
||||
$errorType = 'E_CORE_WARNING';
|
||||
$errorReadable = 'Core Warning';
|
||||
// throw new CoreWarningException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_WARNING;
|
||||
break;
|
||||
case E_COMPILE_ERROR:
|
||||
$errorType = 'E_COMPILE_ERROR';
|
||||
$errorReadable = 'Compile Error';
|
||||
// throw new CompileErrorException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_ERR;
|
||||
break;
|
||||
case E_COMPILE_WARNING:
|
||||
$errorType = 'E_COMPILE_WARNING';
|
||||
$errorReadable = 'Compile Warning';
|
||||
// throw new CoreWarningException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_WARNING;
|
||||
break;
|
||||
case E_USER_ERROR:
|
||||
$errorType = 'E_USER_ERROR';
|
||||
$errorReadable = 'User Error';
|
||||
// handling an sql error
|
||||
if ( $error_description == '(SQL)' ) {
|
||||
echo '<b>SQL Query: </b><code>' . SQLQUERY . '</code><br>';
|
||||
echo '<b>SQL Line: </b><code>' . SQLERRORLINE . '</code><br>';
|
||||
echo '<b>SQL File: </b><code>' . SQLERRORFILE . '</code><br>';
|
||||
}
|
||||
// throw new UserErrorException($error_description, 0, $error_code, $file, $err_line);
|
||||
// $log = LOG_ERR;
|
||||
break;
|
||||
case E_USER_NOTICE:
|
||||
$errorType = 'E_USER_NOTICE';
|
||||
$errorReadable = 'User Notice';
|
||||
// $log = LOG_NOTICE;
|
||||
break;
|
||||
case E_STRICT:
|
||||
$errorType = 'E_STRICT';
|
||||
$errorReadable = 'Strict';
|
||||
// $log = LOG_NOTICE;
|
||||
break;
|
||||
case E_RECOVERABLE_ERROR:
|
||||
$errorType = 'E_RECOVERABLE_ERROR';
|
||||
$errorReadable = 'Recoverable Error';
|
||||
// $log = LOG_WARNING;
|
||||
break;
|
||||
case E_USER_WARNING:
|
||||
$errorType = 'E_USER_WARNING';
|
||||
$errorReadable = 'User Warning';
|
||||
// $log = LOG_WARNING;
|
||||
break;
|
||||
case E_DEPRECATED:
|
||||
$errorType = 'E_DEPRECATED';
|
||||
$errorReadable = 'Deprecated';
|
||||
// $log = LOG_NOTICE;
|
||||
// no break
|
||||
case E_USER_DEPRECATED:
|
||||
$errorType = 'E_USER_DEPRECATED';
|
||||
$errorReadable = 'User Deprecated';
|
||||
// $log = LOG_NOTICE;
|
||||
break;
|
||||
default:
|
||||
$errorType = 'UNKNOWN';
|
||||
$errorReadable = 'Unknown Error';
|
||||
break;
|
||||
}
|
||||
|
||||
echo '<h3>' . $errorReadable . ':</h3>';
|
||||
echo "<b>Error Description: </b><code>{$error_description}" . '</code><br>';
|
||||
echo "<b>File: </b><code>{$file}" . '</code><br>';
|
||||
echo "<b>Line Number: </b><code>{$error_line_number}" . '</code><br>';
|
||||
echo "<b>Error Case: </b><code>{$errorType}" . '</code><br>';
|
||||
echo "<b>Error Code: </b><code>{$error_code}" . '</code><br>';
|
||||
echo "<b>Error Description (fancy): </b><code>{$errstr}" . '</code><br>';
|
||||
echo '<b>PHP Version: </b><code>' . PHP_VERSION . '</code><br>';
|
||||
echo '<b>PHP OS: </b><code>' . PHP_OS . '</code><br>';
|
||||
// $data = [
|
||||
// // 'level' => $log,
|
||||
// 'code' => $error_line_number,
|
||||
// // 'error' => $error,
|
||||
// 'description' => $error_description,
|
||||
// 'file' => $file,
|
||||
// 'line' => $error_line_number,
|
||||
// 'path' => $file,
|
||||
// 'message' => $error . ' (' . $error_line_number . '): ' . $error_description . ' in [' . $file . ', line ' . $error_line_number . ']'
|
||||
// ];
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Acts as a constructor.
|
||||
*/
|
||||
private static function startDebug() {
|
||||
if ( self::status( 'file' ) ) {
|
||||
self::$tempusLogger = new Logger;
|
||||
}
|
||||
if ( self::status( 'console' ) ) {
|
||||
ob_start();
|
||||
self::$tempusDebugger = TempusDebugger::getInstance( true );
|
||||
self::$tempusDebugger->setOption( 'includeLineNumbers', CANARY_SHOW_LINES );
|
||||
// self::$tempusDebugger->setHash( CANARY_SECURE_HASH );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Debug Status.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function status( $flag = null ) {
|
||||
switch ( $flag ) {
|
||||
case 'console':
|
||||
return CANARY_DEBUG_TO_CONSOLE;
|
||||
case 'file':
|
||||
return CANARY_DEBUG_TO_FILE;
|
||||
case 'trace':
|
||||
return CANARY_TRACE_ENABLED;
|
||||
case 'render':
|
||||
return RENDERING_ENABLED;
|
||||
case 'debug':
|
||||
default:
|
||||
return CANARY_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the interface that writes to our log file/console depending on input type.
|
||||
*
|
||||
* @param string $type - Debugging type.
|
||||
* @param string $data - Debugging data.
|
||||
*
|
||||
* @todo make a case statement
|
||||
*/
|
||||
private static function put( $type, $data = null, $params = null ) {
|
||||
if ( ! CANARY_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
if ( strlen( self::$debugLog ) > CANARY_DEBUG_LOG_LIMIT ) {
|
||||
self::$tempusLogger->addLog( 'log', 'Error log too large, possible loop.' );
|
||||
return;
|
||||
}
|
||||
if ( is_object( $data ) ) {
|
||||
$data = 'cannot save objects';
|
||||
}
|
||||
if ( !is_string( $data ) ) {
|
||||
$data = var_export( $data, true );
|
||||
}
|
||||
if ( !empty( self::$lastCall ) ) {
|
||||
$highlight = '';
|
||||
$trimmed_class = trim(self::$lastCall, '\\');
|
||||
$trimmed_class = trim($trimmed_class, '"');
|
||||
$trimmed_class = trim($trimmed_class, "'");
|
||||
$exploded_classname = explode( '\\\\', $trimmed_class );
|
||||
$exploded_classname[1] = '<b>'.$exploded_classname[1].'</b>';
|
||||
$bolded_line = implode( ' \\ ', $exploded_classname );
|
||||
$shortened_name = str_ireplace( 'TheTempusProject', 'TTP', $bolded_line );
|
||||
if ( in_array( $type, ['error','info','warn'])) {
|
||||
$highlight = 'debug-log-' . $type;
|
||||
}
|
||||
$full_line = "<span class='debug-log {$highlight}'><{$shortened_name}>:{$data}</span><br>";
|
||||
self::$debugLog .= $full_line;
|
||||
self::$lastCall = '';
|
||||
}
|
||||
if ( self::status( 'file' ) ) {
|
||||
if ( ! self::$tempusLogger ) {
|
||||
self::startDebug();
|
||||
}
|
||||
switch ( $type ) {
|
||||
case 'error':
|
||||
case 'warn':
|
||||
case 'info':
|
||||
case 'log':
|
||||
case 'debug':
|
||||
self::$tempusLogger->addLog( $type, $data );
|
||||
break;
|
||||
case 'variable':
|
||||
self::$tempusLogger->addLog( 'error', $data );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! self::status( 'console' ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! self::$tempusDebugger ) {
|
||||
self::startDebug();
|
||||
}
|
||||
switch ( $type ) {
|
||||
case 'variable':
|
||||
self::$tempusDebugger->info( $data, $params );
|
||||
break;
|
||||
case 'groupEnd':
|
||||
self::$tempusDebugger->groupEnd();
|
||||
break;
|
||||
case 'trace':
|
||||
self::$tempusDebugger->trace( $data );
|
||||
break;
|
||||
case 'group':
|
||||
if ( $params ) {
|
||||
self::$tempusDebugger->group( $data, $params );
|
||||
} else {
|
||||
self::$tempusDebugger->group( $data );
|
||||
}
|
||||
break;
|
||||
case 'info':
|
||||
self::$tempusDebugger->$type( 'color: #1452ff', '%c' . $data );
|
||||
break;
|
||||
default:
|
||||
self::$tempusDebugger->$type( $data );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a group.
|
||||
*/
|
||||
public static function gend() {
|
||||
if ( self::$group > 0 ) {
|
||||
self::$group--;
|
||||
self::put( 'groupEnd' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a group divider into the console output.
|
||||
*
|
||||
* @param string $data name of the group
|
||||
* @param wild $collapsed if anything is present the group will be collapsed by default
|
||||
*/
|
||||
public static function closeAllGroups() {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
if ( self::$group > 0 ) {
|
||||
while ( self::$group > 0 ) {
|
||||
self::$group--;
|
||||
self::put( 'groupEnd' );
|
||||
}
|
||||
// self::put('log', 'closed all groups.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a group divider into the console output.
|
||||
*
|
||||
* @param string $data name of the group
|
||||
* @param wild $collapsed if anything is present the group will be collapsed by default
|
||||
*/
|
||||
public static function group( $data, $collapsed = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
if ( !empty( $collapsed ) ) {
|
||||
$params = ['Collapsed' => true];
|
||||
self::put( 'group', $data, $params );
|
||||
} else {
|
||||
self::put( 'group', $data );
|
||||
}
|
||||
self::$group++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to print the contents of any variable into the console.
|
||||
*
|
||||
* @param WILD $var - The variable you wish to read.
|
||||
* @param string $data - Optional name for the variable output.
|
||||
*/
|
||||
public static function v( $var, $data = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
if ( !isset( $data ) ) {
|
||||
$data = 'Default Variable label';
|
||||
}
|
||||
self::put( 'variable', $var, $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Socket function for a basic debugging log.
|
||||
*
|
||||
* @param string $data - The debug data.
|
||||
*/
|
||||
public static function log( $data, $params = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
self::put( 'log', $data );
|
||||
if ( !empty( $params ) ) {
|
||||
self::gend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a stack trace from the current calling spot.
|
||||
*
|
||||
* @param string $data the name of the trace
|
||||
*/
|
||||
public static function trace( $data = 'Default Trace' ) {
|
||||
list( $childClass, $caller ) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export( $caller['class'], true );
|
||||
self::group( 'Debug Trace', 1 );
|
||||
self::put( 'trace' );
|
||||
self::gend();
|
||||
}
|
||||
|
||||
/**
|
||||
* Socket function for debugging info.
|
||||
*
|
||||
* @param string $data - The debug data.
|
||||
*/
|
||||
public static function info( $data, $params = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
self::put( 'info', $data );
|
||||
if ( !empty( $params ) ) {
|
||||
self::gend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Socket function for a debugging warning.
|
||||
*
|
||||
* @param string $data - The debug data.
|
||||
*/
|
||||
public static function warn( $data, $params = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
self::put( 'warn', $data );
|
||||
if ( !empty( $params ) ) {
|
||||
self::gend();
|
||||
}
|
||||
}
|
||||
|
||||
public static function debug( $data, $params = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
self::put( 'debug', $data );
|
||||
if ( !empty( $params ) ) {
|
||||
self::gend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Socket function for a debugging error.
|
||||
*
|
||||
* @param string $data - The debug data.
|
||||
*/
|
||||
public static function error( $data, $params = null ) {
|
||||
list($childClass, $caller) = debug_backtrace(false, 2);
|
||||
self::$lastCall = var_export($caller['class'],true);
|
||||
self::put( 'error', $data );
|
||||
if ( CANARY_TRACE_ENABLED ) {
|
||||
self::trace();
|
||||
}
|
||||
if ( !empty( $params ) ) {
|
||||
self::gend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the contents of the debug log.
|
||||
*/
|
||||
public static function dump() {
|
||||
return self::$debugLog;
|
||||
}
|
||||
}
|
78
renamed/classes/customException.php
Normal file
78
renamed/classes/customException.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Classes/CustomException.php
|
||||
*
|
||||
* This class is used exclusively when throwing predefined exceptions.
|
||||
* It will intercept framework thrown exceptions and deal with them however
|
||||
* you choose; in most cases by logging them and taking appropriate responses
|
||||
* such as redirecting to error pages.
|
||||
*
|
||||
* @version 1.0.7
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/libraries/Canary
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary\Classes;
|
||||
|
||||
use Exception;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
|
||||
class CustomException extends Exception {
|
||||
private $originFunction = null;
|
||||
private $exceptionName = null;
|
||||
private $originClass = null;
|
||||
private $data = null;
|
||||
|
||||
/**
|
||||
* This function allows the application to deal with errors
|
||||
* in a dynamic way by letting you customize the response
|
||||
*
|
||||
* @param string $type - The type of the exception being called/thrown.
|
||||
* @param string $data - Any additional data being passed with the exception.
|
||||
*
|
||||
* @example - throw new CustomException('model'); - Calls the model-missing exception
|
||||
*/
|
||||
public function __construct( $type, $data = null ) {
|
||||
$this->originFunction = debug_backtrace()[1]['function'];
|
||||
$this->originClass = debug_backtrace()[1]['class'];
|
||||
$this->exceptionName = $type;
|
||||
$this->data = $data;
|
||||
switch ( $type ) {
|
||||
case 'model':
|
||||
Debug::error( 'Model not found: ' . $data );
|
||||
break;
|
||||
case 'dbConnection':
|
||||
Debug::error( 'Error Connecting to the database: ' . $data );
|
||||
break;
|
||||
case 'DB':
|
||||
Debug::error( 'Unspecified database error: ' . $data );
|
||||
break;
|
||||
case 'view':
|
||||
Debug::error( 'View not found: ' . $data );
|
||||
break;
|
||||
case 'controller':
|
||||
Debug::error( 'Controller not found: ' . $data );
|
||||
Redirect::to( 404 );
|
||||
break;
|
||||
case 'defaultController':
|
||||
Debug::error( 'DEFAULT Controller not found: ' . $data );
|
||||
Redirect::to( 404 );
|
||||
break;
|
||||
case 'method':
|
||||
Debug::error( 'Method not found: ' . $data );
|
||||
Redirect::to( 404 );
|
||||
break;
|
||||
case 'simpleView':
|
||||
Debug::error( 'View not found: ' . $data );
|
||||
break;
|
||||
case 'defaultMethod':
|
||||
Debug::error( 'DEFAULT Method not found: ' . $data );
|
||||
Redirect::to( 404 );
|
||||
break;
|
||||
default:
|
||||
Debug::error( 'Default exception: ' . $data );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
123
renamed/classes/logger.php
Normal file
123
renamed/classes/logger.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* logger.php
|
||||
*
|
||||
* @version 1.0.7
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/libraries/Canary
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary\Classes;
|
||||
|
||||
class Logger {
|
||||
public $file;
|
||||
public $logDirectory;
|
||||
public $logFilePath;
|
||||
|
||||
public function __construct() {
|
||||
$this->setupLogFile();
|
||||
$this->file = fopen( $this->logFilePath, 'a' );
|
||||
fwrite( $this->file, '===================------++++++++++------===================' . PHP_EOL );
|
||||
}
|
||||
|
||||
public function setupLogFile() {
|
||||
$this->logDirectory = rtrim( CANARY_DEBUG_DIRECTORY, DIRECTORY_SEPARATOR );
|
||||
if ( ! is_dir( $this->logDirectory ) ) {
|
||||
mkdir( $this->logDirectory, 0777, true );
|
||||
}
|
||||
|
||||
$currentFile = date('m-d-Y') . '.log';
|
||||
$this->logFilePath = $this->logDirectory . DIRECTORY_SEPARATOR . $currentFile;
|
||||
|
||||
if ( ! file_exists( $this->logFilePath ) ) {
|
||||
touch( $this->logFilePath );
|
||||
chmod( $this->logFilePath, 0777 );
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
fwrite( $this->file, '============================================================' . PHP_EOL );
|
||||
fclose( $this->file );
|
||||
}
|
||||
|
||||
public function addLog( $type = 'log', $log = '' ) {
|
||||
switch ( CANARY_DEBUG_TO_FILE_LEVEL ) {
|
||||
case CANARY_DEBUG_LEVEL_ERROR:
|
||||
$acceptableLoggingLevels = [
|
||||
CANARY_DEBUG_LEVEL_ERROR,
|
||||
];
|
||||
if (! in_array( $type, $acceptableLoggingLevels )) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case CANARY_DEBUG_LEVEL_WARN:
|
||||
$acceptableLoggingLevels = [
|
||||
CANARY_DEBUG_LEVEL_ERROR,
|
||||
CANARY_DEBUG_LEVEL_WARN,
|
||||
];
|
||||
if (! in_array( $type, $acceptableLoggingLevels )) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case CANARY_DEBUG_LEVEL_INFO:
|
||||
$acceptableLoggingLevels = [
|
||||
CANARY_DEBUG_LEVEL_ERROR,
|
||||
CANARY_DEBUG_LEVEL_WARN,
|
||||
CANARY_DEBUG_LEVEL_INFO,
|
||||
];
|
||||
if (! in_array( $type, $acceptableLoggingLevels )) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case CANARY_DEBUG_LEVEL_LOG:
|
||||
$acceptableLoggingLevels = [
|
||||
CANARY_DEBUG_LEVEL_ERROR,
|
||||
CANARY_DEBUG_LEVEL_WARN,
|
||||
CANARY_DEBUG_LEVEL_INFO,
|
||||
CANARY_DEBUG_LEVEL_LOG,
|
||||
];
|
||||
if (! in_array( $type, $acceptableLoggingLevels )) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case CANARY_DEBUG_LEVEL_DEBUG:
|
||||
$acceptableLoggingLevels = [
|
||||
CANARY_DEBUG_LEVEL_ERROR,
|
||||
CANARY_DEBUG_LEVEL_WARN,
|
||||
CANARY_DEBUG_LEVEL_INFO,
|
||||
CANARY_DEBUG_LEVEL_LOG,
|
||||
CANARY_DEBUG_LEVEL_DEBUG,
|
||||
];
|
||||
if (! in_array( $type, $acceptableLoggingLevels )) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
$formattedMessage = $this->timestamp() . $this->typestamp( $type ) . $log . PHP_EOL;
|
||||
fwrite( $this->file, $formattedMessage );
|
||||
}
|
||||
|
||||
private function timestamp() {
|
||||
$dateString = self::getReadableDate( time() );
|
||||
return '['.$dateString.'] - ';
|
||||
}
|
||||
|
||||
private function typestamp( $type ) {
|
||||
$dateString = self::getReadableDate( time() );
|
||||
return '[' . strtoupper( $type ) . '] - ';
|
||||
}
|
||||
|
||||
public static function getReadableDate( $timestamp, $with_timezone = false ) {
|
||||
if ( $with_timezone ) {
|
||||
$date = new \DateTime();
|
||||
$date->setTimestamp( $timestamp );
|
||||
$timezone = new \DateTimeZone( self::getTimezone() );
|
||||
$date->setTimezone( $timezone );
|
||||
$formattedDate = $date->format('Y-m-d H:i:s');
|
||||
return $formattedDate;
|
||||
}
|
||||
return date( 'Y-m-d H:i:s', $timestamp );
|
||||
}
|
||||
}
|
1130
renamed/classes/tempusDebugger.php
Normal file
1130
renamed/classes/tempusDebugger.php
Normal file
File diff suppressed because it is too large
Load Diff
213
renamed/classes/tempusTools.php
Normal file
213
renamed/classes/tempusTools.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* tempus_tools.php
|
||||
*
|
||||
* This is an interface for the Tempus Debugger to interact with TempusTools
|
||||
*
|
||||
* @version 1.0.7
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/libraries/Canary
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Canary\Classes;
|
||||
|
||||
if ( !class_exists( 'TempusDebugger', false ) ) {
|
||||
require_once 'tempus_debugger.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the given data to the TempusTools Chrome Extension.
|
||||
* The data can be displayed in devtools.
|
||||
*
|
||||
* @param mixed $Object
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
function tt() {
|
||||
$instance = TempusDebugger::getInstance( true );
|
||||
$args = func_get_args();
|
||||
return call_user_func_array( [ $instance, 'tt' ], $args );
|
||||
}
|
||||
|
||||
class TempusTools {
|
||||
/**
|
||||
* Set an Insight console to direct all logging calls to
|
||||
*
|
||||
* @param object $console The console object to log to
|
||||
* @return void
|
||||
*/
|
||||
public static function setLogToInsightConsole( $console ) {
|
||||
TempusDebugger::getInstance( true )->setLogToInsightConsole( $console );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable and disable logging to TempusTools
|
||||
*
|
||||
* @param boolean $enabled TRUE to enable, FALSE to disable
|
||||
* @return void
|
||||
*/
|
||||
public static function setEnabled( $enabled ) {
|
||||
TempusDebugger::getInstance( true )->setEnabled( $enabled );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if logging is enabled
|
||||
*
|
||||
* @return boolean TRUE if enabled
|
||||
*/
|
||||
public static function getEnabled() {
|
||||
return TempusDebugger::getInstance( true )->getEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a filter to be used when encoding an object
|
||||
*
|
||||
* Filters are used to exclude object members.
|
||||
*
|
||||
* @param string $class The class name of the object
|
||||
* @param array $filter An array or members to exclude
|
||||
* @return void
|
||||
*/
|
||||
public static function setObjectFilter( $class, $filter ) {
|
||||
TempusDebugger::getInstance( true )->setObjectFilter( $class, $filter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set some options for the library
|
||||
*
|
||||
* @param array $options The options to be set
|
||||
* @return void
|
||||
*/
|
||||
public static function setOptions( $options ) {
|
||||
TempusDebugger::getInstance( true )->setOptions( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options for the library
|
||||
*
|
||||
* @return array The options
|
||||
*/
|
||||
public static function getOptions() {
|
||||
return TempusDebugger::getInstance( true )->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log object to console
|
||||
*
|
||||
* @param mixed $object
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function send() {
|
||||
$args = func_get_args();
|
||||
return call_user_func_array( [ TempusDebugger::getInstance( true ), 'tt' ], $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a group for following messages
|
||||
*
|
||||
* Options:
|
||||
* Collapsed: [true|false]
|
||||
* Color: [#RRGGBB|ColorName]
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $options OPTIONAL Instructions on how to log the group
|
||||
* @return true
|
||||
*/
|
||||
public static function group( $name, $options = null ) {
|
||||
return TempusDebugger::getInstance( true )->group( $name, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a group you have started before
|
||||
*
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function groupEnd() {
|
||||
return self::send( null, null, TempusDebugger::GROUP_END );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log object with label to the console
|
||||
*
|
||||
* @param mixes $object
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function log( $object, $label = null ) {
|
||||
return self::send( $object, $label, TempusDebugger::LOG );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log object with label to the console
|
||||
*
|
||||
* @param mixes $object
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function info( $object, $label = null ) {
|
||||
return self::send( $object, $label, TempusDebugger::INFO );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log object with label to the console
|
||||
*
|
||||
* @param mixes $object
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function warn( $object, $label = null ) {
|
||||
return self::send( $object, $label, TempusDebugger::WARN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log object with label to the console
|
||||
*
|
||||
* @param mixes $object
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function error( $object, $label = null ) {
|
||||
return self::send( $object, $label, TempusDebugger::ERROR );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps key and variable to console
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $variable
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function dump( $key, $variable ) {
|
||||
return self::send( $variable, $key, TempusDebugger::DUMP );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a trace in the console
|
||||
*
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function trace( $label ) {
|
||||
return self::send( $label, TempusDebugger::TRACE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a table in the console
|
||||
*
|
||||
* @param string $label
|
||||
* @param string $table
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function table( $label, $table ) {
|
||||
return self::send( $table, $label, TempusDebugger::TABLE );
|
||||
}
|
||||
}
|
41
renamed/composer.json
Normal file
41
renamed/composer.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "thetempusproject/canary",
|
||||
"type": "library",
|
||||
"description": "Functionality for tracking, logging, and sending log messages to chrome for debugging.",
|
||||
"license": "MIT",
|
||||
"minimum-stability": "dev",
|
||||
"keywords":
|
||||
[
|
||||
"thetempusproject",
|
||||
"php",
|
||||
"tools",
|
||||
"debugging",
|
||||
"logging"
|
||||
],
|
||||
"homepage": "https://thetempusproject.com/libraries/canary",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Joey Kimsey",
|
||||
"email": "Joey@thetempusproject.com",
|
||||
"homepage": "https://JoeyKimsey.com",
|
||||
"role": "Lead Developer"
|
||||
}
|
||||
],
|
||||
"require":
|
||||
{
|
||||
"php": ">=8.1.0"
|
||||
},
|
||||
"autoload":
|
||||
{
|
||||
"psr-4":
|
||||
{
|
||||
"TheTempusProject\\Canary\\Classes\\": "Classes"
|
||||
},
|
||||
"files":
|
||||
[
|
||||
"Config/constants.php",
|
||||
"Bin/Canary.php"
|
||||
]
|
||||
}
|
||||
}
|
58
renamed/config/constants.php
Normal file
58
renamed/config/constants.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
if ( ! defined('CANARY_ENABLED' ) ) {
|
||||
define( 'CANARY_ENABLED', false );
|
||||
}
|
||||
|
||||
// Directories
|
||||
if ( ! defined( 'CANARY_ROOT_DIRECTORY' ) ) {
|
||||
define( 'CANARY_ROOT_DIRECTORY', dirname( __DIR__ ) . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
if ( ! defined( 'CANARY_CONFIG_DIRECTORY' ) ) {
|
||||
define( 'CANARY_CONFIG_DIRECTORY', CANARY_ROOT_DIRECTORY . 'config' . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
|
||||
// Log Levels
|
||||
if ( ! defined('CANARY_DEBUG_LEVEL_ERROR' ) ) {
|
||||
define( 'CANARY_DEBUG_LEVEL_ERROR', 'error' );
|
||||
}
|
||||
if ( ! defined('CANARY_DEBUG_LEVEL_WARN' ) ) {
|
||||
define( 'CANARY_DEBUG_LEVEL_WARN', 'warn' );
|
||||
}
|
||||
if ( ! defined('CANARY_DEBUG_LEVEL_INFO' ) ) {
|
||||
define( 'CANARY_DEBUG_LEVEL_INFO', 'info' );
|
||||
}
|
||||
if ( ! defined('CANARY_DEBUG_LEVEL_LOG' ) ) {
|
||||
define( 'CANARY_DEBUG_LEVEL_LOG', 'log' );
|
||||
}
|
||||
if ( ! defined('CANARY_DEBUG_LEVEL_DEBUG' ) ) {
|
||||
define( 'CANARY_DEBUG_LEVEL_DEBUG', 'debug' );
|
||||
}
|
||||
|
||||
// File Logging
|
||||
if ( ! defined('CANARY_DEBUG_TO_FILE' ) ) {
|
||||
define( 'CANARY_DEBUG_TO_FILE', false );
|
||||
}
|
||||
if ( ! defined( 'CANARY_DEBUG_DIRECTORY' ) ) {
|
||||
define( 'CANARY_DEBUG_DIRECTORY', CANARY_ROOT_DIRECTORY . 'logs' . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
if ( ! defined( 'CANARY_DEBUG_TO_FILE_LEVEL' ) ) {
|
||||
define( 'CANARY_DEBUG_TO_FILE_LEVEL', CANARY_DEBUG_LEVEL_ERROR );
|
||||
}
|
||||
|
||||
if ( ! defined( 'CANARY_SECURE_HASH' ) ) {
|
||||
define( 'CANARY_SECURE_HASH', '' );
|
||||
}
|
||||
if ( ! defined( 'CANARY_SHOW_LINES' ) ) {
|
||||
define( 'CANARY_SHOW_LINES', false );
|
||||
}
|
||||
if ( ! defined('CANARY_DEBUG_TO_CONSOLE' ) ) {
|
||||
define( 'CANARY_DEBUG_TO_CONSOLE', false );
|
||||
}
|
||||
if ( ! defined('CANARY_DEBUG_LOG_LIMIT' ) ) {
|
||||
define( 'CANARY_DEBUG_LOG_LIMIT', 500000 );
|
||||
}
|
||||
|
||||
# Tell the app all constants have been loaded.
|
||||
if ( ! defined('CANARY_CONSTANTS_LOADED' ) ) {
|
||||
define( 'CANARY_CONSTANTS_LOADED', true );
|
||||
}
|
2
renamed/logs/.gitignore
vendored
Normal file
2
renamed/logs/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
2
renamed/vendor/.gitignore
vendored
Normal file
2
renamed/vendor/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
Reference in New Issue
Block a user