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. CF1083(div1)

    A. The Fair Nut and the Best Path 题意:给定有点权,有边权的树,让你选择一条链(也可以是只有一个点),使得点权之和-边权最大. 思路:裸的树形DP,我们用dp[i]表 ...

  2. L3-017 森森快递 (30 分)

    森森开了一家快递公司,叫森森快递.因为公司刚刚开张,所以业务路线很简单,可以认为是一条直线上的N个城市,这些城市从左到右依次从0到(编号.由于道路限制,第i号城市(,)与第(号城市中间往返的运输货物重 ...

  3. 有用的sql语句积累

    ⑴.  sql查询未被外键关联的数据 select * from bb b where not exists (select 1 from aa a where a.bid=b.bid)

  4. 【BZOJ3295】【CQOI2011】动态逆序对

    cdq分治经典例题,然而智商掉线傻逼错误坑了两天 原题: 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你 ...

  5. yocto和bitbake

    一.yocto 1.yocto简介 Yocto 是一个开源社区通过它提供模版.工具和方法帮助开发者创建基于linux内核的定制系统,支持ARM, PPC, MIPS, x86 (32 & 64 ...

  6. MySQL--忘记MYSQL管理员密码

    如root用户密码,可以按照以下方式来修改: STEP1: 停止MySQL服务 ps -ef | grep -v 'grep' | grep 'mysqld' | awk '{print $2}' | ...

  7. Windows Phone 的这几年

    Windows Phone 从2010年10月发布,到如今已经有3年多了.从那时坚持到现在的用户和开发者一定感慨很多吧. 一直关注着这个让人既爱又恨的平台的发展,笔者不仅是使用者,也同时是开发者,这里 ...

  8. ios之runloop笔记

    网上关于runloop的文章不计其数,再此,贴个自认为讲的比较简单明了的文章 http://www.jianshu.com/p/536184bfd163 个人理解: ios的runloop应该是类似于 ...

  9. [模板] KMP字符串匹配标准代码

    之前借鉴了某个模板的代码.我个人认为这份代码写得很好.值得一背. #include<bits/stdc++.h> using namespace std; const int N=1000 ...

  10. SpringMVC中session的使用

    SpringMVC中仍然可以使用传统方式使用session /** * 使用session - 传统方式 */ @RequestMapping("/hello13.action") ...