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写日志公共类的更多相关文章

  1. C#写日志工具类

    代码: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System ...

  2. Delphi 写日志的类

    unit uProgLog; interface uses Windows, SysUtils, SyncObjs; const C_LOG_LEVEL_TRACE = $; C_LOG_LEVEL_ ...

  3. c# 多线程使用队列顺序写日志的类 (需要再优化)

    using System; using System.Collections.Generic; using System.Threading; public class LogManager { // ...

  4. 写日志(log)

    已下为我自己写的一个写日志的类,比较简洁. <?php class Log { /** * @Purpose : 写日志 * @Method Name : writeLog() * @param ...

  5. C#写文本日志帮助类(支持多线程)改进版(不适用于ASP.NET程序)

    由于iis的自动回收机制,不适用于ASP.NET程序 代码: using System; using System.Collections.Concurrent; using System.Confi ...

  6. C#写文本日志帮助类(支持多线程)

    代码: using System; using System.Configuration; using System.IO; using System.Threading.Tasks; namespa ...

  7. 重复造轮子,编写一个轻量级的异步写日志的实用工具类(LogAsyncWriter)

    一说到写日志,大家可能推荐一堆的开源日志框架,如:Log4Net.NLog,这些日志框架确实也不错,比较强大也比较灵活,但也正因为又强大又灵活,导致我们使用他们时需要引用一些DLL,同时还要学习各种用 ...

  8. python win32com 处理excle 写一个公共的类

    利用win32com处理excle,这样可以不管文件是老的xls还是新的xlsx格式,非常方便. 类的源码如下: import win32com.client as win32 class easyE ...

  9. Mybatis包分页查询java公共类

    Mybatis包分页查询java公共类   分页----对于数据量非常大的查询中.是不可缺少的. mybatis底层的分页sql语句因为须要我们自己去手动写.而实现分页显示的时候我们须要依据分页查询条 ...

随机推荐

  1. FREESWITCH 填坑指南

    转接 1.查看网关注册状态 sofia status 2.桥接(未实践) http://wiki.freeswitch.org.cn/wiki/Mod_lua.html#jump10237 frees ...

  2. chapter02 回归模型在''美国波士顿房价预测''问题中实践

    #coding=utf8 # 从sklearn.datasets导入波士顿房价数据读取器. from sklearn.datasets import load_boston # 从sklearn.mo ...

  3. HDU 2111:Saving HDU(贪心)

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. test20181006 石头剪刀布

    题意 分析 考场做法同题解一样. std代码. #include<bits/stdc++.h> using namespace std; template <typename T&g ...

  5. 用vmware安装gho文件心得

    在卡饭学到了不少知识,下面是我的一个心得分享,希望大家能用的上. 用vmware安装gho文件心得 方法1:diskgenius+ghostexp用vm新建一个空白硬盘虚拟机, 记住虚拟机文件的存储位 ...

  6. WINDOWS FTP命令详解

    FTP命令是Internet用户使用最频繁的命令之一,不论是在DOS还是UNIX操作系统下使用FTP,都会遇到大量的FTP内部命令.熟悉并灵活应用FTP的内部命令,可以大大方便使用者,并收到事半功倍之 ...

  7. POJ1135 Domino Effect

    题目:http://poj.org/problem?id=1135 只是求以1为起点的最短路罢了.稍稍判断一下在边上的情况. 多亏提醒:毒数据——n==1!一定要dis [ k ] >= ans ...

  8. tyvj1061Mobile Service

    题目:http://www.joyoi.cn/problem/tyvj-1061 dp.枚举三个人现在的位置. 1.重点:当前必有一人正处在查询点上!于是省掉一维. 2.转移方程枚举上一阶段的 j 和 ...

  9. Java awt组件间的继承关系

    Container的继承关系: Window是可独立存在的容器,其他则不行.

  10. [boost] : test库

    最小化的测试套件minimal_test test库提供一个最小化的测试套件minimal_test, 类似lightweight_test适合入门级测试. 需要包含文件文#include <b ...