Replace runtime logger by Monolog #101

Merged
merged 4 commits into from Dec 22, 2011

Projects

None yet

3 participants

@fzaninotto
Propel member

As decided in the roadmap, this PR removes PEAR::LOG logger and replaces it by Monolog.

refs #23.

@willdurand
Propel member

Seems not mergeable :o

fzaninotto added some commits Dec 11, 2011
@fzaninotto fzaninotto [Monolog] Added ServiceContainer::getLogger().
- Seldaek/monolog is now a dependency
- The service container has the ability to contain several loggers (one per datasource)
- A fallback mechanism allows to keep only one logger
da7249d
@fzaninotto fzaninotto [monolog] Make the Propel::log() method use Monolog.
Propel::log() is now only a proxy to the logger being set in the Service Container.
Note that the logging configuration format changes
49fc1bb
@fzaninotto fzaninotto [monolog] Made per-connection logger possible again.
As planned, this implies passing the connection name to the connection
via the ConnectionManager. It changes two interfaces, but it's not that
big a deal.
The modification also allows us to get rid of the Configuration object
in the ConnectionWrapper, so the next step is to remove this object from
the Runtime code altogether (its features are now handled mostly by the
ServiceContainer).
5f2e787
@fzaninotto
Propel member

Ok, all rebased, should be better now.

@willdurand
Propel member

Hum, my commit broke the PR :o

@willdurand willdurand commented on an outdated diff Dec 22, 2011
documentation/documentation/08-logging.markdown
@@ -283,6 +192,54 @@ Oct 04 00:00:18 propel-bookstore [debug] SELECT bookstore_employee_account.EMPLO
By default, Propel logs all SQL queries, together with the date of the query and the name of the connection.
+### Using a Custom Logger per Connection ###
+
+To log SQL queries for a connection, Propel first looks for a logger named after the connection itself, and falls back to the default logger if no custom logger is defined for the connection.
+
+Using the follofing config, Propel will log SQL queries from the `bookstore` datasource into a `propel_bookstore.log` file, and the SQL queries for all other datasources into a `propel.log` file.
@willdurand
willdurand Dec 22, 2011

s/follofing/following

@willdurand willdurand commented on an outdated diff Dec 22, 2011
documentation/documentation/08-logging.markdown
+
+{% highlight php %}
+<?php
+$con = Propel::getConnection(MyObjPeer::DATABASE_NAME);
+$con->setLogMethods(array(
+ 'exec',
+ 'query',
+ 'execute', // these first three are the default
+ 'beginTransaction',
+ 'commit',
+ 'rollBack',
+ 'bindValue'
+));
+{% endhighlight %}
+
+Note that this list takes into account the methods from both `ConnecitonWrapper` and `StatementWrapper`.
@willdurand
willdurand Dec 22, 2011

s/ConnecitonWrapper/ConnectionWrapper

@willdurand willdurand commented on an outdated diff Dec 22, 2011
src/Propel/Runtime/Connection/ConnectionWrapper.php
@@ -36,7 +36,12 @@ class ConnectionWrapper implements ConnectionInterface
*/
const PROPEL_ATTR_CACHE_PREPARES = -1;
- /**
+ /**
@willdurand
willdurand Dec 22, 2011

indentation error here

@willdurand willdurand commented on an outdated diff Dec 22, 2011
src/Propel/Runtime/Connection/ConnectionWrapper.php
@@ -36,7 +36,12 @@ class ConnectionWrapper implements ConnectionInterface
*/
const PROPEL_ATTR_CACHE_PREPARES = -1;
- /**
+ /**
+ * @var string The datasource name associated to this connection
+ */
+ protected $name;
+
+ /**
@willdurand
willdurand Dec 22, 2011

indentation error here

@willdurand willdurand commented on an outdated diff Dec 22, 2011
src/Propel/Runtime/Connection/ConnectionWrapper.php
*
- * @var array
+ * @var BasicLogger
@willdurand
willdurand Dec 22, 2011

Are you sure it's still a BasicLogger here ?

@willdurand willdurand commented on an outdated diff Dec 22, 2011
src/Propel/Runtime/Connection/ConnectionWrapper.php
}
/**
- * Get the runtime configuration
- *
- * @return Configuration
+ * @return ConnectionInterface
@willdurand
willdurand Dec 22, 2011

Would you mind to add the FQCN here ?

@willdurand willdurand commented on the diff Dec 22, 2011
src/Propel/Runtime/Connection/DebugPDO.php
- * The order in which the logging details are enabled is significant, since it determines the order in
- * which they will appear in the log file.
- *
- * @example // Enable simple query profiling, flagging calls taking over 1.5 seconds as slow:
- * $config = Propel::getConfiguration(Configuration::TYPE_OBJECT);
- * $config->setParameter('debugpdo.logging.details.slow.enabled', true);
- * $config->setParameter('debugpdo.logging.details.slow.threshold', 1.5);
- * $config->setParameter('debugpdo.logging.details.time.enabled', true);
- *
- * @author Francois Zaninotto
- * @author Cameron Brunner <cameron.brunner@gmail.com>
- * @author Hans Lellelid <hans@xmpl.org>
- * @author Christian Abegg <abegg.ch@gmail.com>
- * @author Jarno Rantanen <jarno.rantanen@tkk.fi>
- * @since 2006-09-22
+ * Class kept for BC sake.
*/
class DebugPDO extends ConnectionWrapper
@willdurand
willdurand Dec 22, 2011

Is it still useful to keep BC here ? Propel2 is BC break anyway...

@fzaninotto
fzaninotto Dec 22, 2011

Well, let's take some time to see how debogging (and configuration) goes in practice.

@fzaninotto
Propel member

All typos fixed, and the PR is mergeable.

@willdurand willdurand merged commit 2ee583e into propelorm:master Dec 22, 2011
@stof

Just a thought about the logger. With this implementation, Propel has an hard dependency to Monolog as it is the only logger that can be used. Wouldn't it be better to define a LoggerInterface and provide the implementation using Monolog (this is how we do in Symfony2: we simply have a class extending Monolog\Logger implementing the interface but all methods come from the original Monolog Logger as the interface matches it). This way, people preferring other loggers could use them (for instance people writing an integration between Propel2 and ZF2 could implement the interface on top of Zend\Log).

@fzaninotto
Propel member

I don't agree. Besides, this was discussed in #23. Monolog is very generic, at's already a step forward for Propel. But until PHP has a standard logging interface, adding our own makes things harder for Monolog users.

And if you want to use an existing Zend_Log instance, you can always create a Monolog handler to handler that ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment