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. 批量分割视频opencv

    前言 视频处理过程中,会用到对等长的视频进行处理,此时要对大视频进行分割. 实现步骤 1.批量读取视频集: 2.视频分割: 测试代码 1.批量读取视频集: /********************* ...

  2. stm32 定时器TIM时钟步骤

    1)TIM3 时钟使能 . RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIMx, ENABLE); //时钟使能 2) 初始化定时器参数,设置自动重装值, 分频系数, ...

  3. hdu 5311(暴力)

    题意:要求在一个字符串中找出三段,然后能拼成一个固定的单词,问是否可行 BC周年庆第二题,我枚举了那个单词的切断位置,然后到给的字符串里分别找,然后就没有然后了``` #include<stdi ...

  4. hdu 2063 二分图匹配

    题意:一些女的和一些男的有好感,有好感的能一起坐过山车,问最多能组成多少对 hdu 11 页上少有的算法题,二分图匹配问题,匈牙利算法,对于每一个汉子,看和他有好感的妹子有没有配对了,没有配对过就可以 ...

  5. Cassandra 数据库, python cqlsh命令

    ★  cql操作数据库(cqlsh.bat: python cqlsh命令操作<优缺点:https://blog.csdn.net/vbirdbest/article/details/77662 ...

  6. listening for variable changes in javascript

    https://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript

  7. makefile,让编译更简单

    陈皓 (CSDN) 概述—— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的 ...

  8. LG4197 Peaks

    题意 题目描述 在Bytemountains有N座山峰,每座山峰有他的高度hih_ihi​.有些山峰之间有双向道路相连,共MMM条路径,每条路径有一个困难值,这个值越大表示越难走,现在有QQQ组询问, ...

  9. Start Developing iOS Apps (Swift) 开始开发iOS应用(Swift)

    http://www.cnblogs.com/tianjian/category/704953.html 构建基础的用户界面 Build a Basic UI http://www.cnblogs.c ...

  10. solr 6.2.1环境搭建

    一:Solr简介 Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过 ...