init
This commit is contained in:
46
CODE_OF_CONDUCT.md
Normal file
46
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment include:
|
||||||
|
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||||
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at webmaster@thetempusproject.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||||
|
|
||||||
|
[homepage]: http://contributor-covenant.org
|
||||||
|
[version]: http://contributor-covenant.org/version/1/4/
|
88
CONTRIBUTING.md
Normal file
88
CONTRIBUTING.md
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# Contribution Guidelines for TempusDebugger
|
||||||
|
Contributing to TempusDebugger is completely voluntary and should follow all of the guidelines listed here in order to ensure the highest probability of acceptance. It is highly recommended to use a php linter to automate more of this process. The project is maintained on github and all contributions need to be submitted via pull request to their specific repository under the `dev` branch. In order to contribute, simply follow the instructions for [creating a pull request](#creating-a-pull-request) below.
|
||||||
|
|
||||||
|
## Pull Request Requirements
|
||||||
|
- All revisions must follow TTP naming conventions (see [Naming Conventions](#naming-conventions) Section)
|
||||||
|
- Include a clear and concise explanation of the features or changes included in your revision listed by file.
|
||||||
|
- All code must follow [PSR 2](http://www.php-fig.org/psr/psr-2/) standards
|
||||||
|
- prefer the use of [] for arrays over array()
|
||||||
|
- All functions must be documented with the exception of controller methods (see [Documentation](#documentation) Section)
|
||||||
|
- Controller methods may be doc-blocked when necessary for clarity (see [Documentation](#documentation) Section)
|
||||||
|
- All new Classes must include a class level doc-block (see [Documentation](#documentation) Section)
|
||||||
|
- Any new dependencies will have a longer validation process and should be accompanied by the required information (see [Dependencies](#dependencies) Section)
|
||||||
|
|
||||||
|
## Naming Conventions
|
||||||
|
- File names are to be lower case
|
||||||
|
- All class names must be upper case
|
||||||
|
- Any data being stored as a file must be saved in the `app/` directory, preferably the `app/config/` directory.
|
||||||
|
- Controllers must have a constructor and destructor incorporating the constructor and destructor in the Resources Controller
|
||||||
|
- (This will be an interface requirement soon)
|
||||||
|
- Views must be named using underscores for separation and must be prefixed with view_
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
Whenever a dependency is updated or added, pull requests must include a section that answers the following questions.
|
||||||
|
- Why is this dependency required
|
||||||
|
- Could this be reasonably accomplished within the app by implementing new features in a later version? explain.
|
||||||
|
- What is the latest stable version that can be used
|
||||||
|
- What features are absolutely necessary for your feature or modification to work
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
### Classes
|
||||||
|
|
||||||
|
New classes must be prefaced with a doc-block following this style:
|
||||||
|
```
|
||||||
|
/**
|
||||||
|
* controllers/admin.php
|
||||||
|
*
|
||||||
|
* This is the admin controller.
|
||||||
|
*
|
||||||
|
* @version 3.0
|
||||||
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||||
|
* @link https://TheTempusProject.com/TempusDebugger
|
||||||
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
From top to bottom:
|
||||||
|
- Filename on the second line
|
||||||
|
- A description for the file
|
||||||
|
- The TTP version this file was built for
|
||||||
|
`@version 1.0`
|
||||||
|
- The Authors name or alias and email
|
||||||
|
`@author first last <email@link.com>`
|
||||||
|
- A copy of the MIT license
|
||||||
|
`@license https://opensource.org/licenses/MIT [MIT LICENSE]`
|
||||||
|
- May include a link for more information
|
||||||
|
`@link http://link.com`
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
Functions must be prefaced with a doc-block following this style:
|
||||||
|
```
|
||||||
|
/**
|
||||||
|
* Intended as a self-destruct session. If the specified session does not
|
||||||
|
* exist, it is created. If the specified session does exist, it will be
|
||||||
|
* destroyed and returned.
|
||||||
|
*
|
||||||
|
* @param string $name - Session name to be created or checked
|
||||||
|
* @param string $string - The string to be used if session needs to be
|
||||||
|
* created. (optional)
|
||||||
|
*
|
||||||
|
* @return bool|string - Returns bool if creating, and a string if the
|
||||||
|
* check is successful.
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
From top to bottom:
|
||||||
|
- There must be a description of the functions intended usage on the second line
|
||||||
|
- All parameters should be documented like this
|
||||||
|
`@param [type] $name - description`
|
||||||
|
- Any function with a return statement must also be documented as such
|
||||||
|
`@return [type] - description`
|
||||||
|
|
||||||
|
## Creating a Pull Request
|
||||||
|
This is a simple explanation of how to create a pull request for changes to TempusDebugger. You can find a detailed walk-through on how to [create a pull request](https://help.github.com/articles/creating-a-pull-request/) on github.
|
||||||
|
|
||||||
|
1. First ensure you have followed all the contributing guidelines
|
||||||
|
2. Squash your merge into a single revision. This will make it easier to view the changes as a whole.
|
||||||
|
3. You can submit a pull request [here](https://github.com/TheTempusProject/TempusDebugger/compare)
|
||||||
|
4. Please submit all pull requests to the dev branch or they will be ignored.
|
88
README.md
88
README.md
@ -1,93 +1,21 @@
|
|||||||
# Canary
|
# TempusDebugger
|
||||||
|
#### PHP Library for sending debug messages to Chrome
|
||||||
|
###### Developer(s): Joey Kimsey
|
||||||
|
|
||||||
|
TempusDebugger is a php library that will enable real time debugging messages to be sent to the TempusTools chrome extension.
|
||||||
|
|
||||||
|
**Notice: This code is in _still_ not production ready. This framework is provided as is, use at your own risk.**
|
||||||
## Getting started
|
|
||||||
|
|
||||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
||||||
|
|
||||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
||||||
|
|
||||||
## Add your files
|
|
||||||
|
|
||||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
||||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
||||||
|
|
||||||
```
|
|
||||||
cd existing_repo
|
|
||||||
git remote add origin https://170-187-142-254.ip.linodeusercontent.com/the-tempus-project/canary.git
|
|
||||||
git branch -M main
|
|
||||||
git push -uf origin main
|
|
||||||
```
|
|
||||||
|
|
||||||
## Integrate with your tools
|
|
||||||
|
|
||||||
- [ ] [Set up project integrations](https://170-187-142-254.ip.linodeusercontent.com/the-tempus-project/canary/-/settings/integrations)
|
|
||||||
|
|
||||||
## Collaborate with your team
|
|
||||||
|
|
||||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
||||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
||||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
||||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
||||||
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
||||||
|
|
||||||
## Test and Deploy
|
|
||||||
|
|
||||||
Use the built-in continuous integration in GitLab.
|
|
||||||
|
|
||||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
|
||||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
||||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
||||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
||||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
||||||
|
|
||||||
***
|
|
||||||
|
|
||||||
# Editing this README
|
|
||||||
|
|
||||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
||||||
|
|
||||||
## Suggestions for a good README
|
|
||||||
|
|
||||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
||||||
|
|
||||||
## Name
|
|
||||||
Choose a self-explaining name for your project.
|
|
||||||
|
|
||||||
## Description
|
|
||||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
||||||
|
|
||||||
## Badges
|
|
||||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
||||||
|
|
||||||
## Visuals
|
|
||||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
||||||
|
|
||||||
## Usage
|
To install simply use the composer command:
|
||||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
||||||
|
|
||||||
## Support
|
`php composer.phar require TheTempusProject/TempusDebugger:1.*`
|
||||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
State if you are open to contributions and what your requirements are for accepting them.
|
|
||||||
|
|
||||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
||||||
|
|
||||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
||||||
|
|
||||||
## Authors and acknowledgment
|
|
||||||
Show your appreciation to those who have contributed to the project.
|
|
||||||
|
|
||||||
## License
|
|
||||||
For open source projects, say how it is licensed.
|
|
||||||
|
|
||||||
## Project status
|
REALLLLLY need to update the contributing document for this one.
|
||||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
41
bin/autoload.php
Normal file
41
bin/autoload.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* autoload.php
|
||||||
|
*
|
||||||
|
* Uses the Hermes autoloader if it has been defined.
|
||||||
|
*
|
||||||
|
* @version 3.0
|
||||||
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||||
|
* @link https://TheTempusProject.com/TempusDebugger
|
||||||
|
* @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 );
|
||||||
|
}
|
449
bin/canary.php
Normal file
449
bin/canary.php
Normal file
@ -0,0 +1,449 @@
|
|||||||
|
<?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 3.0
|
||||||
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||||
|
* @link https://TheTempusProject.com/Core
|
||||||
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||||
|
*/
|
||||||
|
namespace TheTempusProject\Canary;
|
||||||
|
|
||||||
|
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 ) > 50000 ) {
|
||||||
|
self::$tempusDebugger->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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
213
classes/TempusTools.php
Normal file
213
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 3.0
|
||||||
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||||
|
* @link https://TheTempusProject.com/TempusDebugger
|
||||||
|
* @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 );
|
||||||
|
}
|
||||||
|
}
|
108
classes/logger.php
Normal file
108
classes/logger.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* logger.php
|
||||||
|
*
|
||||||
|
* @version 3.0
|
||||||
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||||
|
*/
|
||||||
|
namespace TheTempusProject\Canary\Classes;
|
||||||
|
use TheTempusProject\Bedrock\Functions\Date;
|
||||||
|
|
||||||
|
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 = Date::getReadableDate( time() );
|
||||||
|
return '['.$dateString.'] - ';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function typestamp( $type ) {
|
||||||
|
$dateString = Date::getReadableDate( time() );
|
||||||
|
return '[' . strtoupper( $type ) . '] - ';
|
||||||
|
}
|
||||||
|
}
|
1130
classes/tempus_debugger.php
Normal file
1130
classes/tempus_debugger.php
Normal file
File diff suppressed because it is too large
Load Diff
27
composer.json
Normal file
27
composer.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "thetempusproject/tempusdebugger",
|
||||||
|
"type": "library",
|
||||||
|
"description": "Framework for sending php messages to chrome for in-browser debugging.",
|
||||||
|
"license": "MIT",
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"keywords": ["php","tools","debugging","thetempusproject"],
|
||||||
|
"homepage": "https://github.com/TheTempusProject/TempusDebugger",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Joey Kimsey",
|
||||||
|
"email": "Joey@thetempusproject.com",
|
||||||
|
"homepage": "https://TheTempusProject.com",
|
||||||
|
"role": "Lead Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.4.0"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"classmap": [
|
||||||
|
"TempusDebugger.php",
|
||||||
|
"TempusTools.php"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
53
config/constants.php
Normal file
53
config/constants.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
# Tell the app all constants have been loaded.
|
||||||
|
define( 'CANARY_CONSTANTS_LOADED', true );
|
Reference in New Issue
Block a user