logistcloud / logging-bundle
logist.cloud LoggingBundle
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.6.0
- symfony/symfony: 2.8.*
This package is auto-updated.
Last update: 2019-08-08 03:11:16 UTC
README
Add to your app/config/parameters.yml.dist
:
parameters:
logging.config_dir: 'Resources/config'
Composer
Run the command $ php composer.phar require logistcloud/logging-bundle:dev-default
.
Composer will install bundle to logistcloud/logging-bundle
directory.
Add to your app/config/config.yml
:
logging:
types:
error: '%logging.config_dir%/error.yml'
exception: '%logging.config_dir%/exception.yml'
low_error: '%logging.config_dir%/low_error.yml'
denied: '%logging.config_dir%/denied.yml'
not_found: '%logging.config_dir%/not_found.yml'
high_error: '%logging.config_dir%/high_error.yml'
failed: '%logging.config_dir%/failed.yml'
auth: '%logging.config_dir%/auth.yml'
granted: '%logging.config_dir%/granted.yml'
file: '%logging.config_dir%/file.yml'
entity: '%logging.config_dir%/entity.yml'
controller: '%logging.config_dir%/controller.yml'
event: '%logging.config_dir%/event.yml'
actions: '%logging.config_dir%/actions.yml'
Add to your app/AppKernel.php
:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
//...
new LoggingBundle\LoggingBundle()
);
return $bundles;
}
//...
}
?>
Put the migration in the directory app/DoctrineMigrations
and run: php app/console doctrine:migrations:migrate 20171201110753
Using
Example of use
Predefined entities for logging are located in the Entity
directory. They must be inherited from EntityBase
class.
In your controller:
<?php
#...
use LoggingBundle\Entity\Log;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
#...
/**
* @Route("/", name="homepage")
* @return Response
*/
public function indexAction()
{
$logger = $this->get('logist.cloud.logger'); // Get the logging service
$logger->log(
[new Log()], // Adding entities
[[
'userId' => 1,
'orderId' => 1,
'message' => 'test test', // required
'tenderId' => 1,
'channel' => 1,
'level' => $logger::$ERROR // required
]], // Value of the fields to be logged
[], // Related entities, if necessary
[['test.png']], // Related files, if necessary
true // flag for use Monolog
); // Logging of a record
$logs = $logger->get(Log::class); // Getting a list of database logs with any level
$logs = $logger->get(Log::class, ['level' => $logger::$ERROR]); // Getting a list of database logs with a level equal to ERROR.
// Equivalently $logs = $logger->getErrors(Log::class);
$logs = $logger->get(Log::class, ['level' => $logger::$ERROR], ['id' => 'desc'], 0, 10); // Getting a list of database logs with a level equal to ERROR + sorting, offset and limit
$logs = $logger->get(Log::class, $logger::$ERROR | $logger::$AUTH); // Getting a list of database logs with a level equal to ERROR and AUTH.
echo '<pre>';
return new Response(print_r($logs, true));
}
#...
?>
Example configuration for logging level "Error"
Add to your vendor/logistcloud/logging-bundle/Resources/config/error.yml
:
default:
size: 1048576 # maximum size of the log file
datetime: 'd.m.Y H:i:s' # date format
output: '[%%datetime%%] %%channel%%.%%level_name%%: %%message%%' # %%context%% %%extra%% # format for a message
related_files: ' files: %s' # related files
related_entities: ' entities: %s' # related entities
log:
path: '' # path to log files
filename: '' # name of the log file
json:
path: '' # path to json files
filename: '' # name of the json file
db:
rows_per_table: 1000 # number of rows in the table partition
error:
log: true # logging to the log file
json: true # logging to the json file
db: true # database logging
Example configuration for logging actions
Add to your vendor/logistcloud/logging-bundle/Resources/config/actions.yml
:
default:
size: 1024
datetime: 'd.m.Y H:i:s'
output: '[%%datetime%%] %%channel%%.%%level_name%%: %%message%%' # %%context%% %%extra%%
message: 'User %s went to route %s'
related_files: ' files: %s'
related_entities: ' entities: %s'
log:
path: ''
filename: ''
json:
path: ''
filename: ''
db:
rows_per_table: 10
actions:
LoggingBundle\Controller\DefaultController::indexAction:
action:
log: true
json: true
db: true
message: 'User %s viewed the home page'