- 浏览: 803868 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
xieye:
jetty插件有好几个版本,1.6,1.7,1.8
我选的是用 ...
tapestry入门(翻译)3 导入项目到eclipse -
xieye:
还有,
注:第2部分时,需要先安装jetty,我自己在安装过程 ...
tapestry入门(翻译)3 导入项目到eclipse -
xieye:
说明一下:实际使用中,导入时我并没有错误。2、我把eclips ...
tapestry入门(翻译)3 导入项目到eclipse -
xieye:
其实还是有一些先决条件的。1是外部环境,2是进步是阶段性的(意 ...
(转载文章)如何愉悦起来:一位精神治疗师的见解 -
mandy_yanzi:
我都已经饿7天了坚持为了我的衣衣
身体健康的问题
phalcon自带的日志文件类,有两个麻烦之处。
1、路径不能自动创建
2、打印消息非得要求是字符串。
自定义类如下:
<?php
use Phalcon\Logger\Adapter\File as FileAdapter;
use Phalcon\Logger\AdapterInterface;
/**
* 自定义 phalcon 日志类
*
* 解决两大痛点:
* 1、路径不能自动创建
* 2、打印消息非得要求是字符串。
*
* 使用方式
*
* $logger = SuperLogger::getInstance(SuperLogger::CLIENT_LOG);
* $logger
* ->info( 'This is a {message}',
* [
* 'message' => time()
* ] )
* ->log( time() )
* ->log(Logger::NOTICE, time() )
* ->error( ['aa'=>11111,'b'=>22222] );
*
* echo "读取日志:".$logger->getPath()."<br>";
* echo file_get_contents($logger->getPath());
*
* 也可以构造方法参数为空,再 select,或 setPath
*
* Class SuperLogger
*
* @method AdapterInterface setFormatter(FormatterInterface $formatter)
* @method FormatterInterface getFormatter()
* @method AdapterInterface setLogLevel($level)
* @method AdapterInterface log($type, $message = null, array $context = null)
* @method AdapterInterface debug($message, array $context = null)
* @method AdapterInterface error($message, array $context = null)
* @method AdapterInterface info($message, array $context = null)
* @method AdapterInterface notice($message, array $context = null)
* @method AdapterInterface warning($message, array $context = null)
* @method AdapterInterface alert($message, array $context = null)
* @method AdapterInterface emergency($message, array $context = null)
* @method AdapterInterface begin()
* @method AdapterInterface commit()
*
*
* @author yyy
*/
class SuperLogger
{
/**
* @var FileAdapter
*/
protected $logger;
protected $file; // 文件完整路径
protected $baseDir;// 预定义日志文件基路径
/**
* 这里自定义一些常量。日志类型。
*/
const HTTP_LOG = 1;
const CLIENT_LOG = 2;
const MENU_LOG = 3;
const PATH_ARR =[
self::HTTP_LOG => 'http/',
self::CLIENT_LOG => 'client/',
self::MENU_LOG => 'menu/',
];
/**
* 这里自定义默认日志根路径。
*
* @param mixed $file
*/
public function __construct( $file = null)
{
$this->baseDir = BASE_PATH . '/cache/logs/';
if ($file) {
if (is_int($file)) {
$this->select($file);
} else {
$this->setPath($file);
}
}
}
public static function getInstance( $file = null):self
{
return new self($file);
}
/**
* 选择不同的日志类型,自行修改。
*
* @param $type
* @return $this
*/
public function select(int $type=null):self
{
if (in_array( $type, array_keys( self::PATH_ARR) )) {
$this->setPath($this->baseDir . self::PATH_ARR[$type] . date("Ymd") . '.log');
} else {
$this->setPath($this->baseDir . date("Ymd") . '.log');
}
return $this;
}
public function getPath(): string
{
return $this->file;
}
public function setPath(string $file):self
{
$this->file = $file;
$folder = preg_replace('#^(.+)/[^/]+$#', '$1', $file);
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
$this->logger = new FileAdapter($file);
return $this;
}
function __call($funName, $arguments)
{
if ($this->logger == null) {
$this->select();
}
if (in_array($funName, ['debug', 'error', 'info', 'notice', 'warning', 'alert', 'emergency',])
|| ($funName == 'log' && (!(is_int($arguments[0]) && $arguments[0] >= 0 && $arguments[0] <= 9)))
) {
if (is_array($arguments[0])) {
$arguments[0] = var_export($arguments[0], 1);
} else {
$arguments[0] = strval($arguments[0]);
}
$this->logger->$funName(...$arguments);
return $this;
} elseif ($funName == 'log' && is_int($arguments[0]) && $arguments[0] >= 0 && $arguments[0] <= 9) {
if (is_array($arguments[1])) {
$arguments[1] = var_export($arguments[1], 1);
} else {
$arguments[1] = strval($arguments[1]);
}
$this->logger->$funName(...$arguments);
return $this;
} else {
return $this->logger->$funName(...$arguments);
}
}
}
1、路径不能自动创建
2、打印消息非得要求是字符串。
自定义类如下:
<?php
use Phalcon\Logger\Adapter\File as FileAdapter;
use Phalcon\Logger\AdapterInterface;
/**
* 自定义 phalcon 日志类
*
* 解决两大痛点:
* 1、路径不能自动创建
* 2、打印消息非得要求是字符串。
*
* 使用方式
*
* $logger = SuperLogger::getInstance(SuperLogger::CLIENT_LOG);
* $logger
* ->info( 'This is a {message}',
* [
* 'message' => time()
* ] )
* ->log( time() )
* ->log(Logger::NOTICE, time() )
* ->error( ['aa'=>11111,'b'=>22222] );
*
* echo "读取日志:".$logger->getPath()."<br>";
* echo file_get_contents($logger->getPath());
*
* 也可以构造方法参数为空,再 select,或 setPath
*
* Class SuperLogger
*
* @method AdapterInterface setFormatter(FormatterInterface $formatter)
* @method FormatterInterface getFormatter()
* @method AdapterInterface setLogLevel($level)
* @method AdapterInterface log($type, $message = null, array $context = null)
* @method AdapterInterface debug($message, array $context = null)
* @method AdapterInterface error($message, array $context = null)
* @method AdapterInterface info($message, array $context = null)
* @method AdapterInterface notice($message, array $context = null)
* @method AdapterInterface warning($message, array $context = null)
* @method AdapterInterface alert($message, array $context = null)
* @method AdapterInterface emergency($message, array $context = null)
* @method AdapterInterface begin()
* @method AdapterInterface commit()
*
*
* @author yyy
*/
class SuperLogger
{
/**
* @var FileAdapter
*/
protected $logger;
protected $file; // 文件完整路径
protected $baseDir;// 预定义日志文件基路径
/**
* 这里自定义一些常量。日志类型。
*/
const HTTP_LOG = 1;
const CLIENT_LOG = 2;
const MENU_LOG = 3;
const PATH_ARR =[
self::HTTP_LOG => 'http/',
self::CLIENT_LOG => 'client/',
self::MENU_LOG => 'menu/',
];
/**
* 这里自定义默认日志根路径。
*
* @param mixed $file
*/
public function __construct( $file = null)
{
$this->baseDir = BASE_PATH . '/cache/logs/';
if ($file) {
if (is_int($file)) {
$this->select($file);
} else {
$this->setPath($file);
}
}
}
public static function getInstance( $file = null):self
{
return new self($file);
}
/**
* 选择不同的日志类型,自行修改。
*
* @param $type
* @return $this
*/
public function select(int $type=null):self
{
if (in_array( $type, array_keys( self::PATH_ARR) )) {
$this->setPath($this->baseDir . self::PATH_ARR[$type] . date("Ymd") . '.log');
} else {
$this->setPath($this->baseDir . date("Ymd") . '.log');
}
return $this;
}
public function getPath(): string
{
return $this->file;
}
public function setPath(string $file):self
{
$this->file = $file;
$folder = preg_replace('#^(.+)/[^/]+$#', '$1', $file);
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
$this->logger = new FileAdapter($file);
return $this;
}
function __call($funName, $arguments)
{
if ($this->logger == null) {
$this->select();
}
if (in_array($funName, ['debug', 'error', 'info', 'notice', 'warning', 'alert', 'emergency',])
|| ($funName == 'log' && (!(is_int($arguments[0]) && $arguments[0] >= 0 && $arguments[0] <= 9)))
) {
if (is_array($arguments[0])) {
$arguments[0] = var_export($arguments[0], 1);
} else {
$arguments[0] = strval($arguments[0]);
}
$this->logger->$funName(...$arguments);
return $this;
} elseif ($funName == 'log' && is_int($arguments[0]) && $arguments[0] >= 0 && $arguments[0] <= 9) {
if (is_array($arguments[1])) {
$arguments[1] = var_export($arguments[1], 1);
} else {
$arguments[1] = strval($arguments[1]);
}
$this->logger->$funName(...$arguments);
return $this;
} else {
return $this->logger->$funName(...$arguments);
}
}
}
发表评论
-
召唤神龙 - 安装 centos 8, php 8, mysql 8, laravel 8 的整套 php 运行环境
2020-11-27 16:26 550本文编写时间:2020-11-27 传说集齐龙珠可以召唤神 ... -
centos8 使用阿里镜像快速安装php7.4套件
2020-11-15 00:48 662centos8 使用阿里镜像快速安装php7.4套件 本文只 ... -
centos7 使用阿里镜像快速安装php7.4套件
2020-11-15 00:32 999本文只考虑centos7 今日 2020-11-16 rem ... -
composer常用命令
2020-11-05 14:46 998列出当前全局配置 composer config -l -g ... -
期待centos8+php8 + mysql8 + laravel8,8888
2020-10-29 19:24 378期待centos8+php8 + mysql8 目前主要使用 ... -
ubuntu 安装 php7.4以及各类插件
2020-10-24 13:20 894ubuntu 安装 php7.4以及各类插件 安装系统 最近 ... -
宝塔定义站点
2020-02-24 10:41 2宝塔定义站点。 1111111111111111111111 ... -
让php-fpm以root账号运行
2020-02-19 21:41 689一般来说,我们没有这种需求,但是当需要时, 可以让php-fp ... -
将代码部署到coding.net
2020-01-10 14:20 536coding.net 是一个git仓库,有免费有收费。 首先 ... -
php部署工具deployer技巧 - vendor目录创建
2020-01-06 12:06 801deployer是个好东西,可是每次都composer ,其实 ... -
自定义redis多个实例
2020-01-04 01:17 576假如多个项目部署到同一台服务器,有时会被redis的各项目前缀 ... -
推荐使用php的部署工具 deployer
2020-01-03 16:48 804php部署代码可以使用 https://deployer.or ... -
使用composer 类库 cachetool 清除opcache 的缓存
2020-01-03 16:38 872php的生产服务器上,需要把opche打开。 但有时,会被缓 ... -
laravel容器学习体会
2019-12-31 15:11 565根据文档与实测结果 假设我在app下建一个Services目 ... -
自定义后台的使用
2019-12-18 05:22 359如果自己写后台,保存用户的表单请求值 所有的情况如下: 1 ... -
phalcon 自定义事件使用的多种方式
2019-12-16 20:43 709方法1:官方文档的方式。 这是控制器: public ... -
phalcon对控制器返回值的使用以输出json
2019-12-16 19:17 726在phalcon里,控制器的Action的方法的返回值没啥用。 ... -
phalcon数据库DB使用实例
2019-12-12 17:12 586整理了一下phalcon的db使用,写了个demo。 ... -
php-redis5.0降级成php-redis4.3
2019-08-22 00:01 832最新版本的php的redis插件,版本是5.0 但是可能会有 ... -
aes加密解密php和java互通代码
2019-08-20 20:19 1078代码主要来源如下,但是注意做了修改: https://gist ...
相关推荐
Logme-Phalcon Logme 是一个基于 phalconPHP 的日志和报表系统
PhalconPHP 3.4.0 更新日志:2018-05-28添加Phalcon\Mvc\Router::attach直接将路由对象添加到路由器#13326中;增加了侦听请求的功能:beforeAuthorizationResolve和request:afterAuthorizationResolve事件,这种...
开发者不需要学习和使用 C 语言的功能, 因为所有的功能都以 PHP 类的方式暴露出来,可以直接使用。 Phalcon 也是松耦合的,可以根据项目的需要任意使用其他对象。Phalcon 不只是为了卓越的性能, 我们的目标是让它...
phalcon开发工具 phalcon-tools
Phalcon7 (高性能 PHP 7框架) v1.2.3更新日志 该版本修复了 Model、Security 和 Request 中的 BUG。 新增了 `PhalconIntrusiveAvltree` 类 Phalcon7 (高性能 PHP 7框架)页面展示 相关阅读 同类推荐:程序框架
无需学习和使用 C 语言,所有函数都以 PHP 类的方式曾现。Phalcon 是一个松耦合的框架。 Phalcon 2.0 基于高性能编译语言Zephir,Zephir的目的是提供一个全新的更简单的语法来编写PHP扩展。 Phalcon 1.x还...
开发者不需要学习和使用 C 语言的功能, 因为所有的功能都以 PHP 类的方式暴露出来,可以直接使用。 Phalcon 也是松耦合的,可以根据项目的需要任意使用其他对象。 Phalcon 不只是为了卓越的性能, 我们的目标是让...
phalcon 中文文档 全中文手册 网页格式 放在环境中 或直接打开查看
Phalcon 3.0.0 中文文档 Phalcon 3.0.0 中文文档 Phalcon 3.0.0 中文文档
Phalcon 是什么?¶ Phalcon 是开源、全功能栈、使用 C 扩展编写、针对高性能优化的 PHP 5 框架。 开发者不需要学习和使用 C 语言的功能, 因为所有的功能都以 PHP 类的方式暴露出来,可以直接使用。 Phalcon 也是...
Phalcon is optimized for high performance. Its unique architecture allows the framework to always be memory resident, offering its functionality whenever its needed, without expensive file stats and ...
phalcon 2.0.0版本64位 包含PHP5.3、PHP5.4、PHP5.5、PHP5.6 本资料共包含以下附件: phalcon_x64_VC9_php5.3.9_2.0.0.zip phalcon_x64_VC9_php5.3.9_2.0.0_nts.zip phalcon_x64_VC9_php5.4.0_2.0.0.zip phalcon...
Phalcon的PhpStorm代码提示说明 Phalcon的PhpStorm代码提示说明
Phalcon 官方最新版 v3.3 的mobi格式的文档: Phalcon is an open source full stack framework for PHP, written as a C-extension. Phalcon is optimized for high performance. Its unique architecture allows ...
phalcon框架的demo
phalcon-v2.0.10 文档,大部分已翻译为中文
phalcon 最快的php框架 没有之一 phalcon2.06中文手册 入门配置教程 两个DEMO项目 学习phalcon 一步到位
phalcon手册Welcome to Phalcon framework. Our mission is to give you an advanced tool for developing the faster web sites and applications with PHP.
phalcon 框架 IDE代码提示 phpstrom NetBeans 等IDE 使用的代码提示
phalcon-debugbar, Phalcon框架的强大调试和探查器工具 Phalcon Debugbar将调试栏与 Phalcon框架集成。中文说明特性正常请求捕获Ajax请求捕获重定向请求链捕获简单应用,多模块应用和微型应用支持收集的数据持久:...