In my bootstrap, I have the following:
$di->setShared('logger', function() use ($di) {
// TODO: DRY. Check app/config/database.php
$connection;
switch (strtolower(($di->get('dbconfig')->dbtype))) {
case 'mysql':
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
'host' => $di->get('dbconfig')->dbhost,
'username' => $di->get('dbconfig')->dbuid,
'password' => $di->get('dbconfig')->dbpwd,
'dbname' => $di->get('dbconfig')->dbname
));
break;
case 'sqlite':
$connection = new \Phalcon\Db\Adapter\Pdo\Sqlite(array(
'dbname' => $GLOBALS['APPDIR'] . '/' . $di->get('dbconfig')->dbname
));
break;
}
$logger = new \Phalcon\Logger\Adapter\Database('system', array(
'db' => $connection,
'table' => 'system_log'
));
// The "type" column is probably informative, but isn't human friendly.
$formatter = new \Phalcon\Logger\Formatter\Line();
$formatter->setFormat('%type% - %message% - %date');
$formatter->setDateFormat('c');
$logger->setFormatter($formatter);
return $logger;
});
In my controller, I have this action:
public function indexAction() {
$this->logger->log('hello!');
}
The logger is working as expected, but the formatter appears to be getting ignored:
sqlite> select * from system_log;
106|system|7|hello!|1477589666
Am I implementing the formatter wrong, or does the logger database adapter not accept formatting? Seeing as how it extends the existing adapter, I expect it to behave as the rest, but I haven't delved deep into the code.