码迷,mamicode.com
首页 > Web开发 > 详细

【PHP】打印log方法

时间:2014-07-16 19:39:14      阅读:394      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   文件   数据   

  我用的是medoo数据库框架,直接把log添加到数据库中,使用时需要导入medoo文件。

Log.php

<?php
require (‘../dao/medoo.php‘);

function logI($tag, $message) {
    input("i", $tag, $message);
}

function logE($tag, $message) {
    input("e", $tag, $message);
}

function logW($tag, $message) {
    input("w", $tag, $message);
}
function logD($tag, $message) {
    input("d", $tag, $message);
}

function input($type, $tag, $message) {
    $db = new medoo(null);
    $db->insert("en_log", array (
    "l_id" => uuid(), "l_type" => $type, "l_tag" => $tag, "l_msg" => $message));
}

/**
 * 生成UUID
 */
function uuid($prefix = ‘‘){
    $chars = md5(uniqid(mt_rand(), true));
    $uuid  = substr($chars,0,8) . ‘-‘;
    $uuid .= substr($chars,8,4) . ‘-‘;
    $uuid .= substr($chars,12,4) . ‘-‘;
    $uuid .= substr($chars,16,4) . ‘-‘;
    $uuid .= substr($chars,20,12);
    return $prefix . $uuid;
}
?>

 

下面是mysql数据库结构,我用的是uuid做表的主键

CREATE TABLE `en_log` (
  `l_id` char(36) NOT NULL,
  `l_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `l_type` enum(‘i‘,‘d‘,‘w‘,‘e‘) NOT NULL,
  `l_tag` char(50) NOT NULL,
  `l_msg` text NOT NULL,
  PRIMARY KEY (`l_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

我知道PHP打印log肯定还有更好的方式可以提出。

 

 

【PHP】打印log方法,布布扣,bubuko.com

【PHP】打印log方法

标签:style   blog   color   使用   文件   数据   

原文地址:http://www.cnblogs.com/markdev/p/3837267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!