2017 © Pedro Peláez
 

symfony-bundle log-bundle

Symfony NTILogBundle

image

nti/log-bundle

Symfony NTILogBundle

  • Wednesday, June 6, 2018
  • by ntidev
  • Repository
  • 3 Watchers
  • 2 Stars
  • 208 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 6 Versions
  • 12 % Grown

The README.md

NTILogBundle

Installation

  1. Install the bundle using composer:
$ composer require ntidev/log-bundle "dev-master"
  1. Add the bundle configuration to the AppKernel
public function registerBundles()
{
    $bundles = array(
        ...
        new NTI\LogBundle\NTILogBundle(),
        ...
    );
}
  1. Setup the configuration in the config.yml
# NTI
nti_log:
    exclude: [ 'JMose\CommandSchedulerBundle\Entity\ScheduledCommand' ]     # default: []

The exclude allows you to exclude logging for specific entities that change at a rapid rate (for example the User entity usually registers changes when users log in), (*1)

  1. Update the database schema
$ php app/console doctrine:schema:update

Usage

  1. Get the Logging service
$logger = $container->get('nti.logger');

The following methods are available for logging:, (*2)

logNotice($message, $action = Log::ACTION_INFO, $entity = null)
logSuccess($message, $action = Log::ACTION_INFO, $entity = null)
logWarning($message, $action = Log::ACTION_INFO, $entity = null) 
logDebug($message, $action = Log::ACTION_DEBUG, $entity = null)
logError($message, $action = Log::ACTION_INFO, $entity = null)    
logException(\Exception $ex) 
logSlack($message, $level = Log::LEVEL_NOTICE, $entity = null) 

Example:, (*3)

$service->logDebug("Hello World")

Event Listeners

The bundle comes with 2 event subscribers: DoctrineEventSubscriber and KernelExceptionListerner., (*4)

The DoctrineEventSubscriber will listener for the following events:, (*5)

  • PostPersist
  • PostUpdate
  • PostRemove

And it will log the changes automatically into the database., (*6)

The KernelExceptionListener will capture all exceptions and log them into the database as well. However, if you capture an exception you must manually log it with the service, for example:, (*7)

try {
    ...
    $em->flush()
} catch(\Exception $ex) {
    $this->get('nti.logger')->logException($ex);
    ...
}

Slack Integration

If the NexySlackBundle is used, you can integrate this bundle to throw the information to a channel in Slack as well., (*8)

The configuration piece as shown above serves to configure how the NTILogBundle should post to Slack:, (*9)

# NTI
nti_log:
    ...    
    # In case NexySlackBundle is used
    nexy_slack:
        enabled:    # default: false
        replicate_logs: true     # default: false
        replicate_levels: [ERROR, DEBUG]   # default: [ERROR]
        channel: "#alertchannel"  # default: empty, required

# NexySlackBundle
nexy_slack:
    # The Slack API Incoming WebHooks URL.
    endpoint: "[see https://api.slack.com/tokens to generate the webhook for this app]"

Todo

  • Make the entity configurable and also the property used to get the username

The Versions

06/06 2018

dev-master

9999999-dev

Symfony NTILogBundle

  Sources   Download

MIT

The Requires

 

by Benjamin Vison

logbundle

06/06 2018

v1.3.0

1.3.0.0

Symfony NTILogBundle

  Sources   Download

MIT

The Requires

 

by Benjamin Vison

logbundle

01/12 2017

v1.2.0

1.2.0.0

Symfony NTILogBundle

  Sources   Download

MIT

The Requires

 

by Benjamin Vison

logbundle

10/11 2017

1.1.0.x-dev

1.1.0.9999999-dev

Symfony NTILogBundle

  Sources   Download

MIT

The Requires

 

by Benjamin Vison

logbundle

10/11 2017

v1.1.0

1.1.0.0

Symfony NTILogBundle

  Sources   Download

MIT

The Requires

 

by Benjamin Vison

logbundle

13/12 2016

v1.0.0

1.0.0.0

Symfony NTILogBundle

  Sources   Download

MIT

The Requires

 

by Benjamin Vison

logbundle