eventhorizon/log-bundle

EventHorizonLogBundle

v1.0.4 2015-03-10 19:18 UTC

README

This bundle is designed to store log messages in the MongodDB.

Installation

Add EventHorizonLogBundle in your composer.json:

{
    "require": {
        // ...
        "eventhorizon/log-bundle": "dev-master"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update eventhorizon/log-bundle

Configuration

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new EventHorizon\LogBundle\EventHorizonLogBundle(),
    );
}

Usage - example

<?php

namespace EventHorizon\ShoppingBundle\Controller;

use JMS\DiExtraBundle\Annotation as DI;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

/**
 * Promotion controller.
 *
 * @Route("/promotion")
 */
class PromotionController extends Controller
{
    /**
     * @DI\Inject("doctrine.orm.entity_manager")
     */
    private $em;

    /**
     * @DI\Inject("event_horizon_log")
     */
    private $log;
//..
    /**
     * @return \EventHorizon\ShoppingBundle\Entity\Promotion
     */
    private function getPromotionObject($promotionId)
    {
        $employee = $this->getEmployeeObject();
        $company = $employee->getCompany();

        $promotion = $this->em->getRepository('EventHorizonShoppingBundle:Promotion')->getPromotionsByIdAndCompanyV1($promotionId, $company);

        if (!($promotion)) {
            $message = "EventHorizonShoppingBundle:Promotion:getPromotionObject id=".$promotionId." userId=".$this->security->getToken()->getUser()->getId();
            $this->log->logNotice($message);

            throw $this->createNotFoundException('Unable to find Promotion entity.');
        }

        return $promotion;
    }
}

Usage - methods and standard log levels

add($content, $level) addDebug($content) addInfo($content) addNotice($content) addWarning($content) addError($content) addCritical($content) addAlert($content) addEmergency($content) logAlert($message) logCritical($message) logDebug($message) logEmergency($message) logError($message) logInfo($message) logNotice($message) logWarning($message)

level_debug = 100 level_info = 200 level_notice = 250 level_warning = 300 level_error = 400 level_critical = 500 level_alert = 550 level_emergency = 600