How to install
You can download the github version.
Or using composer : composer require zaeder/js-logger-bundle
How to configure
1 - Add bundle to app/AppKernel.php
<?php
2 - Add your user entity class to app/config/config.yml
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
[...],
new Zaeder\Link4mailingBundle\ZaederJsLoggerBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
[...]
}
return $bundles;
}
[...]
}monolog:
handlers:
[...]
js_logger:
type: stream
path: "%kernel.logs_dir%/js_%kernel.environment%.log"
level: debug
channels: [jsLogger]
zaeder_js_logger:
allowed_levels: ['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY']
monolog_channel: jsLogger
Define mode
There is two modes : manual and auto.
It's defined by a twig extension function which you have to defined before your scripts.
{{ zaeder_js_logger() }} : Manual mode
{{ zaeder_js_auto_logger() }} : Automatic mode
Manual mode
In this mode, the developer have to use jsLogger(level, message, contextData) to log his message.
Function's arguments :
level : Must be in ['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'] and defined in config file (mandatory)
message : Message to log (mandatory)
contextData : Other information like the stack, the file, the user agent, … (optional)
Automatic mode
In this mode, the javascripts errors will be logged automatically. The methods console.debug, console.info, console.warn, console.error either if the levels defined in config file allowed it.