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语句因为须要我们自己去手动写.而实现分页显示的时候我们须要依据分页查询条 ...
随机推荐
- Windows自动执行java脚本
1.打包 idea 1).File-Project Structure-Arifacts 2). 3). 4). 5). 目录位于 根目录/out\artifacts\ 2.Windows定时任务 ...
- ACM大牛的BLOG(转)
Twilightgod CUSThttp://blog.csdn.net/twilightgodAekdycoin FZU http://hi.baidu.com/aekdycoinForeverli ...
- WPF控件NumericUpDown (转)
WPF控件NumericUpDown示例 (转载请注明出处) 工具:Expression Blend 2 + Visual Studio 2008 语言:C# 框架:.Net Framework 3. ...
- 我的nginx iis 负载均衡学习(环境搭建)
1,下载并安装nginx 比较简单 2,进行网站的配置 我使用了我的IIS 站点中已经拥有的两个站点 3,进行nginx 的配置 配置如下: 在server 节点之前添加如下的配置: upstream ...
- JS 网页键盘钩子
使用write技术把脚本和代码写入文件,即使查看原文及也无法看到原代码,下面是具体的代码,直接保存就可以运行============================================== ...
- Linux 安装Jdk、mysql、apache、php、tomcat、nginx
Jdk 安装分三步:第一步,上传跟 linux 位数相同的 jdk tar 包,解压:第二步:解压 tar 包,配置环境变量,且 source 一下 /etc/profile:第三步:检查版本 第一步 ...
- spring boot 项目文件结构
启动类建议放在RootPackage的原因: 根据SpringBoot的内置实现,Spring默认从@ComponentScan注解所在的位置开始向后扫描,也就是说,只要我们将组件放在启动类所在的Ro ...
- bzoj 3687 简单题——bitset
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3687 关于 bitset :https://blog.csdn.net/snowy_smil ...
- Gradle Build速度加快终极方法(android studio)
Android Studio用起来越来越顺手,但是却发现Build的速度实在不敢恭维,在google和度娘了几把(....)之后,大体就是分配更高的内存,步骤:Setting-->搜索gradl ...
- 在word中输入任意角度旋转图片
Sub 图片旋转任意角度() Dim sha As Shape, isa As InlineShape Static s As Integer Application.ScreenUpdating = ...