Skip to content

Instantly share code, notes, and snippets.

@wdalmut
Created September 12, 2012 13:31
Show Gist options
  • Save wdalmut/3706609 to your computer and use it in GitHub Desktop.
Save wdalmut/3706609 to your computer and use it in GitHub Desktop.
Just a Zend\Log\Logger on MySQL
CREATE DATABASE a_log_database;
USE a_log_database;
CREATE TABLE IF NOT EXISTS `log_table_name` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`priority` int(11) NOT NULL,
`priorityName` varchar(45) NOT NULL,
`message` varchar(255) NOT NULL,
`extra_ip` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
<?php
require_once __DIR__ . '/vendor/autoload.php';
$dbconfig = array(
'driver' => 'Mysqli',
'database' => 'a_log_database',
'host' => 'localhost',
'username' => 'username',
'password' => 'password'
);
$db = new Zend\Db\Adapter\Adapter($dbconfig);
$writer = new Zend\Log\Writer\Db($db, 'log_table_name');
$logger = new Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('Informational message', array('ip' => '192.168.0.1'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment