Skip to content

Commit

Permalink
Pluginkit compatibility (composer installer)
Browse files Browse the repository at this point in the history
Merge pull request #4 from bnomei/master: pluginkit and other improvements
  • Loading branch information
Bart Vandeputte committed Feb 7, 2019
2 parents 3314c12 + 61cb6c3 commit 5983cef
Show file tree
Hide file tree
Showing 26 changed files with 1,867 additions and 50 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[*.{css,scss,less,js,json,ts,sass,html,hbs,mustache,phtml,html.twig,md,yml}]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false

[site/templates/**.php]
indent_size = 2

[site/snippets/**.php]
indent_size = 2

[package.json,.{babelrc,editorconfig,eslintrc,lintstagedrc,stylelintrc}]
indent_style = space
indent_size = 2
26 changes: 25 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# OS files
.DS_Store
vendor
.php_cs.cache

/vendor/**/.markdown

# files of Composer dependencies that are not needed for the plugin
/vendor/**/.*
/vendor/**/*.json
/vendor/**/*.txt
/vendor/**/*.md
/vendor/**/*.yml
/vendor/**/*.yaml
/vendor/**/*.xml
/vendor/**/*.dist
/vendor/**/readme.php
/vendor/**/LICENSE
/vendor/**/COPYING
/vendor/**/VERSION
/vendor/**/docs/*
/vendor/**/example/*
/vendor/**/examples/*
/vendor/**/test/*
/vendor/**/tests/*
/vendor/**/php4/*
/vendor/getkirby/composer-installer
14 changes: 14 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('kirby')
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
])
->setFinder($finder)
;
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "bvdputte/kirby-log",
"description": "Logging utility for Kirby - based on katzgrau/KLogger",
"version": "0.0.1",
"version": "1.0.0",
"license": "MIT",
"type": "kirby-plugin",
"require": {
"getkirby/composer-installer": "^1.1",
"katzgrau/klogger": "^1.2"
},
"autoload": {
"files": [
"config.php"
],
"psr-4": {
"bvdputte\\kirbyLog\\": "src/"
}
Expand All @@ -19,5 +18,9 @@
"name": "Bart Vandeputte",
"email": "bart.vdputte@gmail.com"
}
]
],
"config": {
"optimize-autoloader": true,
"sort-packages": true
}
}
52 changes: 45 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions config.php

This file was deleted.

24 changes: 23 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';
@include_once __DIR__ . '/vendor/autoload.php';

Kirby::plugin('bvdputte/kirbylog', [
'options' => [
'logfolder' => 'kirbylogs',
'logname' => 'kirbylog.log',
'defaultloglevel' => 'info'
],
]);

/*
A little Kirby helper function
*/
if (! function_exists("kirbyLog")) {
function kirbyLog($name = null, $opts = [])
{
$logName = $name ?? kirby()->option("bvdputte.kirbylog.logname");

$kirbyLog = new bvdputte\kirbyLog\Logger($logName, $opts);

return $kirbyLog;
}
}
21 changes: 14 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
A little log utility you can use with Kirby 3.
It's a wrapper around [KLogger](https://github.com/katzgrau/KLogger).

⚠️ This plugin is currently a playground for me to test the new Kirby plugin system. Do not use in production _yet_. ⚠️

## Installation

Put the `kirby-log` folder in your `site/plugins` folder, then install via composer:

```ssh
cd site/plugins/kirby-queue
composer install --no-dev
```
- unzip [master.zip](https://github.com/bvdputte/kirby-log/archive/master.zip) as folder `site/plugins/kirby-log` or
- `git submodule add https://github.com/bvdputte/kirby-log.git site/plugins/kirby-log` or
- `composer require bvdputte/kirby-log`

## Usage

Expand Down Expand Up @@ -95,3 +91,14 @@ kirbyLog("kirbylog.log")->log("My message", "error");
1. The default location where logfiles will be saved is `/site/kirbylogs/`. You can change `kirbylogs` foldername by using setting it via the options `$kirby->option("bvdputte.kirbylog.logfolder", "myownfoldername");`.
2. The default logname is `kirbylog.log`. Change it with `$kirby->option("bvdputte.kirbylog.logname", "custom-logname.log");`.
3. The default loglevel is `info`. Change it with `$kirby->option("bvdputte.kirbylog.defaultloglevel, "debug");`. Be sure to [use a valid PSR-3 loglevel](#loglevel).


## Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/bvdputte/kirby-log/issues/new).

## License

[MIT](https://opensource.org/licenses/MIT)

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
17 changes: 10 additions & 7 deletions src/Logger.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
namespace bvdputte\kirbyLog;

use Psr\Log\LogLevel;

class Logger {
class Logger
{
public $logger;

protected $options = [];
Expand All @@ -18,11 +20,11 @@ class Logger {
"debug"
];

function __construct($name = null, array $options = [], $logLevelThreshold = LogLevel::DEBUG) {

public function __construct($name = null, array $options = [], $logLevelThreshold = LogLevel::DEBUG)
{
$logroot = kirby()->roots()->site() . DS . kirby()->option("bvdputte.kirbylog.logfolder");

if(isset($name)) {
if (isset($name)) {
$this->options["filename"] = $name;
}

Expand All @@ -41,17 +43,18 @@ function __construct($name = null, array $options = [], $logLevelThreshold = Log
// return $this->logger;
// }

public function log($message, $loglevel = null, $context = []) {
public function log($message, $loglevel = null, $context = [])
{
$logger = $this->logger;

// Fallback to default loglevel if none passed
$level = isset($loglevel) ? $loglevel : kirby()->option("bvdputte.kirbylog.defaultloglevel");

//if (method_exists($logger, $level)) {
if(array_search($level, $this->logLevels)) {
if (array_search($level, $this->logLevels)) {
$logger->$level($message, $context);
} else {
echo("Error: invalid loglevel code. Please use a PSR-3 loglevel code.");
}
}
}
}
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit9dfc62fa15f5312aa86488031097cc96::getLoader();
Loading

0 comments on commit 5983cef

Please sign in to comment.