承接 jkey/monolog-mssql 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jkey/monolog-mssql

Composer 安装命令:

composer require jkey/monolog-mssql

包简介

A handler for Monolog that sends messages to MSSQL

README 文档

README

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, with some changes. The table and columns are not created or removed automatically.

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

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

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

<?php
require __DIR__ . '/../vendor/autoload.php';
//Import class
use Monolog\Logger;
use Jkey\Monolog\Handler\MSSQLHandler;

$pdo = new PDO('sqlsrv:Server=localhost;Database=log', 'myuser', 'mypass');

//Create logger
$log = new Logger('name');
$log->pushHandler(new MSSQLHandler($pdo, "log", array('username', 'userid'), \Monolog\Logger::DEBUG));

//Now you can use the logger, and further attach additional information
$log->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.

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 82
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固