PHP写日志公共类
Txl_Log.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*
*
*
* @package TXL
* @filesource
*/ // ------------------------------------------------------------------------ /**
* Logging Class
*
* @package TXL
* @subpackage Libraries
* @category Logging
*/
class Txl_Log { protected $_log_path;
protected $_date_fmt = 'Y-m-d H:i:s';
protected $_enabled = TRUE; /**
* Constructor
*/
public function __construct()
{
$config =& get_config();
//$config['log_path'] = '/data/logs/weili_sz/app/';
$this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/'; if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
{
$this->_enabled = FALSE;
} if ($config['log_date_format'] != '')
{
$this->_date_fmt = $config['log_date_format'];
}
} // -------------------------------------------------------------------- public function log_curl($url, $post, $rs, $time=0, $api='curl')
{
if (is_array($post)) {
$post = json_encode($post);
} if (is_array($rs)) {
$rs = json_encode($rs);
} $this->write_log($url."\t[params]".$post."\t[ret]".$rs.($time?"\t".$time:"\t"), $api);
} /**
* Write Log File
*
* Generally this function will be called using the global log_message() function
*
* @param string the error level
* @param string the error message
* @param bool whether the error is a native PHP error
* @return bool
*/
public function write_log($msg, $type='interface')
{
if ($this->_enabled === FALSE)
{
return FALSE;
} //$filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
$filepath = $this->_log_path.$type.'-'.date('Ymd').'.php';
$message = ''; if ( ! file_exists($filepath))
{
$message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
} if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE)) //define('FOPEN_WRITE_CREATE', 'ab');
{
return FALSE;
} $message .= date($this->_date_fmt). "\t".$msg."\n"; flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp); @chmod($filepath, FILE_WRITE_MODE);//define('FILE_WRITE_MODE', 0666);
return TRUE;
} }
// END Log Class
PHP写日志公共类的更多相关文章
- C#写日志工具类
代码: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System ...
- Delphi 写日志的类
unit uProgLog; interface uses Windows, SysUtils, SyncObjs; const C_LOG_LEVEL_TRACE = $; C_LOG_LEVEL_ ...
- c# 多线程使用队列顺序写日志的类 (需要再优化)
using System; using System.Collections.Generic; using System.Threading; public class LogManager { // ...
- 写日志(log)
已下为我自己写的一个写日志的类,比较简洁. <?php class Log { /** * @Purpose : 写日志 * @Method Name : writeLog() * @param ...
- C#写文本日志帮助类(支持多线程)改进版(不适用于ASP.NET程序)
由于iis的自动回收机制,不适用于ASP.NET程序 代码: using System; using System.Collections.Concurrent; using System.Confi ...
- C#写文本日志帮助类(支持多线程)
代码: using System; using System.Configuration; using System.IO; using System.Threading.Tasks; namespa ...
- 重复造轮子,编写一个轻量级的异步写日志的实用工具类(LogAsyncWriter)
一说到写日志,大家可能推荐一堆的开源日志框架,如:Log4Net.NLog,这些日志框架确实也不错,比较强大也比较灵活,但也正因为又强大又灵活,导致我们使用他们时需要引用一些DLL,同时还要学习各种用 ...
- python win32com 处理excle 写一个公共的类
利用win32com处理excle,这样可以不管文件是老的xls还是新的xlsx格式,非常方便. 类的源码如下: import win32com.client as win32 class easyE ...
- Mybatis包分页查询java公共类
Mybatis包分页查询java公共类 分页----对于数据量非常大的查询中.是不可缺少的. mybatis底层的分页sql语句因为须要我们自己去手动写.而实现分页显示的时候我们须要依据分页查询条 ...
随机推荐
- c++ json 详解
一. 使用jsoncpp解析json Jsoncpp是个跨平台的开源库,首先从http://jsoncpp.sourceforge.net/上下载jsoncpp库源码,我下载的是v0.5.0,压缩包大 ...
- jqprint 打印分页
再要分页的结尾处加上<div style="page-break-after:always;"></div> 就可以了
- CTF-练习平台-WEB之 签到题
一.签到题 根据提示直接加群在群公告里就能找到~
- Windows下同一台机器上elasticsearch集群的配置以及elasticsearch-head插件的使用
ElasticSearch是一个基于Lucene的开源搜索服务器,现已经被越来越多的企业运用于项目当中,笔者为了学习es在自己机器上简单的搭建了一个es集群,此文权当记录. 1.我用到的压缩包 下载地 ...
- JavaWeb学习总结(二)-修改Tomcat服务器的端口(半年之后再总结)
一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件(hibernate.cfg.xml是核心配置文件). 如果想修改Tom ...
- Maven的dependency type属性
官方地址: http://maven.apache.org/ref/3.5.2/maven-model/maven.html (搜索:Some examples are jar, war, ejb-c ...
- hadoop零基础入门之DKH安装准备
前几天去参加了一个线下的聚会,参加聚会的基本都是从事互联网工作的.会上有人提到了区块链,从而引发了一场关于大数据方面的探讨.我也是从去年才正式接触大数据,一直在学习hadoop.相信接触过hadoop ...
- MySQL索引分类和各自用途
一. MySQL: 索引以B树格式保存 Memory存储引擎可以选择Hash或BTree索引,Hash索引只能用于=或<=>的等式比较. 1.普通索引:create index on Ta ...
- DokuWiki
DokuWiki 1.点我,点我,dokuwiki使用教程一 2.点我,点我,dokuwiki使用教程二 3.点我,点我,dokuWiki语法 4.点我,点我,WARP插件
- Mybatis常见面试题 一
1.#{}和${}的区别是什么? 注:这道题是面试官面试我同事的. 答:${}是Properties文件中的变量占位符,它可以用于标签属性值和sql内部,属于静态文本替换,比如${driver}会被静 ...