PHPackages                             jkey/monolog-mssql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jkey/monolog-mssql

ActiveLibrary[Database &amp; ORM](/categories/database)

jkey/monolog-mssql
==================

A handler for Monolog that sends messages to MSSQL

v1.0.5.1(7y ago)0601MITPHP

Since Sep 13Pushed 6y ago1 watchersCompare

[ Source](https://github.com/jkey/monolog-mssql)[ Packagist](https://packagist.org/packages/jkey/monolog-mssql)[ Docs](https://github.com/jkey/monolog-mssql)[ RSS](/packages/jkey-monolog-mssql/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (1)Versions (9)Used By (0)

monolog-mssql
=============

[](#monolog-mssql)

Microsoft SQL Server Handler for Monolog, which allows to store log messages in a MSSQL Table. It can log text messages to a specific table. The class further allows to use extra attributes as database field, which are can be used for later analyzing and sorting.

This is a fork from [waza-ari/monolog-mysql](https://github.com/waza-ari/monolog-mysql), with some changes. The table and columns are not created or removed automatically.

Installation
============

[](#installation)

monolog-mssql is available via composer. Just add the following line to your required section in composer.json and do a `php composer.phar update`.

```
"jkey/monolog-mssql": ">1.0.0"

```

After that you have to create your database table. We need the following structure, which you are free to extend.

```
CREATE TABLE myLog
  (
    id         BIGINT        NOT NULL
                             IDENTITY(1,1)
                             PRIMARY KEY,
    channel    NVARCHAR(255) NOT NULL,
    level      INT           NOT NULL,
    message    NTEXT         NOT NULL,
    time       INT           NOT NULL
  );
```

Usage
=====

[](#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:

- **$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 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

Examples
========

[](#examples)

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

```
