This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1ffa1c3
Showing
12 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"pluginName":"Tail","pluginDescription":"An console command to tail your Craft log","pluginVersion":"1.0.0","pluginAuthorName":"Superbig","pluginVendorName":"superbig","pluginAuthorUrl":"https://superbig.co","pluginAuthorGithub":"superbigco","codeComments":"","pluginComponents":["consolecommands"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# CRAFT ENVIRONMENT | ||
.env.php | ||
.env.sh | ||
.env | ||
|
||
# COMPOSER | ||
/vendor | ||
|
||
# BUILD FILES | ||
/bower_components/* | ||
/node_modules/* | ||
/build/* | ||
/yarn-error.log | ||
|
||
# MISC FILES | ||
.cache | ||
.DS_Store | ||
.idea | ||
.project | ||
.settings | ||
*.esproj | ||
*.sublime-workspace | ||
*.sublime-project | ||
*.tmproj | ||
*.tmproject | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
config.codekit3 | ||
prepros-6.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Tail Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## 1.0.0 - 2018-09-09 | ||
### Added | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Superbig | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Tail plugin for Craft CMS 3.x | ||
|
||
An console command to tail your Craft log | ||
|
||
![Plugin icon](resources/icon.png) | ||
|
||
## Requirements | ||
|
||
This plugin requires Craft CMS 3.0.0-beta.23 or later. | ||
|
||
## Installation | ||
|
||
To install the plugin, follow these instructions. | ||
|
||
1. Open your terminal and go to your Craft project: | ||
|
||
cd /path/to/project | ||
|
||
2. Then tell Composer to load the plugin: | ||
|
||
composer require superbig/craft-tail | ||
|
||
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Tail. | ||
|
||
## Tail Overview | ||
|
||
-Insert text here- | ||
|
||
## Using Tail | ||
|
||
-Insert text here- | ||
|
||
Brought to you by [Superbig](https://superbig.co) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "superbig/craft-tail", | ||
"description": "An console command to tail your Craft log", | ||
"type": "craft-plugin", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"tail" | ||
], | ||
"support": { | ||
"docs": "https://github.com/superbigco/craft-tail/blob/master/README.md", | ||
"issues": "https://github.com/superbigco/craft-tail/issues" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Superbig", | ||
"homepage": "https://superbig.co" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "^3.0.0-RC1", | ||
"symfony/process": "^3.3|^4.0" | ||
|
||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"superbig\\tail\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"name": "Tail", | ||
"handle": "tail", | ||
"hasCpSettings": false, | ||
"hasCpSection": false, | ||
"changelogUrl": "https://raw.githubusercontent.com/superbigco/craft-tail/master/CHANGELOG.md", | ||
"class": "superbig\\tail\\Tail" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Tail plugin for Craft CMS 3.x | ||
* | ||
* An console command to tail your Craft log | ||
* | ||
* @link https://superbig.co | ||
* @copyright Copyright (c) 2018 Superbig | ||
*/ | ||
|
||
namespace superbig\tail; | ||
|
||
|
||
use Craft; | ||
use craft\base\Plugin; | ||
use craft\services\Plugins; | ||
use craft\events\PluginEvent; | ||
use craft\console\Application as ConsoleApplication; | ||
|
||
use yii\base\Event; | ||
|
||
/** | ||
* Class Tail | ||
* | ||
* @author Superbig | ||
* @package Tail | ||
* @since 1.0.0 | ||
* | ||
*/ | ||
class Tail extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var Tail | ||
*/ | ||
public static $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $schemaVersion = '1.0.0'; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
if (Craft::$app instanceof ConsoleApplication) { | ||
$this->controllerNamespace = 'superbig\tail\console\controllers'; | ||
} | ||
|
||
Event::on( | ||
Plugins::class, | ||
Plugins::EVENT_AFTER_INSTALL_PLUGIN, | ||
function (PluginEvent $event) { | ||
if ($event->plugin === $this) { | ||
} | ||
} | ||
); | ||
|
||
Craft::info( | ||
Craft::t( | ||
'tail', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
/** | ||
* Tail plugin for Craft CMS 3.x | ||
* | ||
* An console command to tail your Craft log | ||
* | ||
* @link https://superbig.co | ||
* @copyright Copyright (c) 2018 Superbig | ||
*/ | ||
|
||
namespace superbig\tail\console\controllers; | ||
|
||
use craft\helpers\FileHelper; | ||
use craft\helpers\Path; | ||
use superbig\tail\Tail; | ||
|
||
use Craft; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Finder\Finder; | ||
use yii\console\Controller; | ||
use yii\helpers\Console; | ||
|
||
|
||
/** | ||
* Default Command | ||
* | ||
* @author Superbig | ||
* @package Tail | ||
* @since 1.0.0 | ||
*/ | ||
class DefaultController extends Controller | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @var string The type of log to tail (web, queue, your-plugin) | ||
*/ | ||
public $type = 'web'; | ||
|
||
/** | ||
* @var string How many lines to display initially | ||
*/ | ||
public $lines = null; | ||
|
||
/** | ||
* @var string Clear terminal output | ||
*/ | ||
public $clear = false; | ||
|
||
/** | ||
* @var string Hide stack traces | ||
*/ | ||
public $hideStackTraces = false; | ||
|
||
public function options($actionID) | ||
{ | ||
return [ | ||
'lines', 'clear', 'hideStackTraces', 'type', | ||
]; | ||
} | ||
|
||
public function optionAliases() | ||
{ | ||
return [ | ||
'l' => 'lines', | ||
't' => 'type', | ||
'c' => 'clear', | ||
]; | ||
} | ||
|
||
/** | ||
* Tail the latest logfile | ||
* | ||
* @return mixed | ||
*/ | ||
public function actionIndex() | ||
{ | ||
|
||
$logDirectory = Craft::$app->getPath()->getLogPath(); | ||
|
||
if (!$path = $this->findLatestLogFile($logDirectory, $this->type)) { | ||
$this->warn("Could not find a log file in `{$logDirectory}`."); | ||
|
||
return; | ||
} | ||
|
||
$lines = $this->lines; | ||
$filters = $this->getFilters(); | ||
$tailCommand = "tail " . ($lines ? "-n {$lines}" : "") . "-f " . escapeshellarg($path) . " {$filters}"; | ||
|
||
$this->handleClearOption(); | ||
|
||
(new Process($tailCommand)) | ||
->setTty(true) | ||
->setTimeout(null) | ||
->run(function($type, $line) { | ||
$this->handleClearOption(); | ||
$this->output->write($line); | ||
}); | ||
|
||
return $result; | ||
} | ||
|
||
protected $signature = 'tail | ||
{--lines=0 : Output the last number of lines} | ||
{--H|hide-stack-traces : Filter out the stack traces} | ||
{--clear : Clear the terminal screen}'; | ||
|
||
|
||
protected function findLatestLogFile(string $directory, $type = 'web') | ||
{ | ||
$logFile = FileHelper::findFiles($directory, ['only' => [$type . '.log']]); | ||
|
||
return $logFile[0] ?? false; | ||
} | ||
|
||
protected function handleClearOption() | ||
{ | ||
if (!$this->clear) { | ||
return; | ||
} | ||
|
||
$this->stdout(sprintf("\033\143\e[3J")); | ||
} | ||
|
||
protected function getFilters() | ||
{ | ||
if ($this->hideStackTraces) { | ||
return '| grep -i -E "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:"'; | ||
} | ||
} | ||
} |
Oops, something went wrong.