Skip to content

Instantly share code, notes, and snippets.

@nielsmouthaan
Created October 10, 2012 22:05
Show Gist options
  • Save nielsmouthaan/3868779 to your computer and use it in GitHub Desktop.
Save nielsmouthaan/3868779 to your computer and use it in GitHub Desktop.
Riverline\DynamoDBBundle class for MonoLogger

For a Symfony2 project I'm using Riverline\DynamoDBBundle to connect my web app to DynamoDB, an highly elastic database in the cloud. It offers some great functions making mutations a lot easier than just using the raw PHP SDK offered by Amazon. Such a feature is the logger feature: it enables you to quickly find stats about queries. By default, Riverline\DynamoDBBundle offers a simple EchoLogger which simply prints its information in the browser. As Symfony is packaged with a great logger called Monolog, I created a simple class that exports Riverline's DynamoDBBundle log information to Monolog. As a result, log information is not printed in your browser directly but you can see its related items in the profiler of Symfony.

This gist is part of a tutorial which can be found here: http://www.nielsmouthaan.nl/riverlinedynamodbbundle-class-for-monologger

<?php
namespace Acme\DemoBundle\Logger;
class MonoLogger implements \Riverline\DynamoDB\Logger\Logger
{
protected $logger;
protected $minLevel;
public function __construct($logger, $minLevel = \Riverline\DynamoDB\Logger\Logger::INFO)
{
$this->logger = $logger;
$this->minLevel = $minLevel;
}
public function log($message, $level = Logger::INFO)
{
if ($level >= $this->minLevel) {
if($level === \Riverline\DynamoDB\Logger\Logger::DEBUG) {
$this->logger->debug($message);
} else if($level === \Riverline\DynamoDB\Logger\Logger::INFO) {
$this->logger->info($message);
} else if($level === \Riverline\DynamoDB\Logger\Logger::WARN) {
$this->logger->warn($message);
} else if($level === \Riverline\DynamoDB\Logger\Logger::ERROR) {
$this->logger->err($message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment