2017 © Pedro Peláez
 

library monolog-mysql

A handler for Monolog that sends messages to MySQL

image

wazaari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  • Sunday, April 23, 2017
  • by waza-ari
  • Repository
  • 11 Watchers
  • 97 Stars
  • 114,913 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 48 Forks
  • 8 Open issues
  • 8 Versions
  • 9 % Grown

The README.md

monolog-mysql

MySQL Handler for Monolog, which allows to store log messages in a MySQL Table. It can log text messages to a specific table, and creates the table automatically if it does not exist. The class further allows to dynamically add extra attributes, which are stored in a separate database field, and can be used for later analyzing and sorting., (*1)

HELP WANTED

As I do not use this project myself anymore and I do not find the time to maintain this project as it deserves I would be happy to find someone taking it over. Please contact me at danielherrmann+gitlab@posteo.de if you'd be interesting to take over that project. Thanks!, (*2)

Installation

monolog-mysql is available via composer. Just add the following line to your required section in composer.json and do a php composer.phar update., (*3)

"wazaari/monolog-mysql": ">1.0.0"

Usage

Just use it as any other Monolog Handler, push it to the stack of your Monolog Logger instance. The Handler however needs some parameters:, (*4)

  • $pdo PDO Instance of your database. Pass along the PDO instantiation of your database connection with your database selected.
  • $table The table name where the logs should be stored
  • $additionalFields simple array of additional database fields, which should be stored in the database. The columns are created automatically, and the fields can later be used in the extra context section of a record. See examples below. Defaults to an empty array()
  • $level can be any of the standard Monolog logging levels. Use Monologs statically defined contexts. Defaults to Logger::DEBUG
  • $bubble Defaults to true
  • $skipDatabaseModifications Defines whether we should skip any attempts to sync current database state with what's requested by the code (includes creating the table and adding / dropping fields). Defaults to false

If $skipDatabaseModifications is set to true, please use the following query as a template to create the log table (with additional fields, if necessary), (*5)

CREATE TABLE `log` (
    id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, channel VARCHAR(255), level INTEGER, message LONGTEXT, time INTEGER UNSIGNED, INDEX(channel) USING HASH, INDEX(level) USING HASH, INDEX(time) USING BTREE
)

Examples

Given that $pdo is your database instance, you could use the class as follows:, (*6)

//Import class
use MySQLHandler\MySQLHandler;

//Create MysqlHandler
$mySQLHandler = new MySQLHandler($pdo, "log", array('username', 'userid'), \Monolog\Logger::DEBUG);

//Create logger
$logger = new \Monolog\Logger($context);
$logger->pushHandler($mySQLHandler);

//Now you can use the logger, and further attach additional information
$logger->addWarning("This is a great message, woohoo!", array('username'  => 'John Doe', 'userid'  => 245));

License

This tool is free software and is distributed under the MIT license. Please have a look at the LICENSE file for further information., (*7)

The Versions

23/04 2017

dev-development

dev-development https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Herrmann

database log logging monolog mysql

04/04 2017

dev-master

9999999-dev https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql

13/02 2017

v1.0.4

1.0.4.0 https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql

03/09 2015

dev-pr/7

dev-pr/7 https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql

13/07 2015

v1.0.3

1.0.3.0 https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql

16/02 2015

v1.0.2

1.0.2.0 https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql

25/11 2014

v1.0.1

1.0.1.0 https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql

13/09 2014

v1.0.0

1.0.0.0 https://github.com/waza-ari/monolog-mysql

A handler for Monolog that sends messages to MySQL

  Sources   Download

MIT

The Requires

 

by Daniel Herrmann

database log logging monolog mysql