---
title: "个人小工具mylog最新"
author: "lxmgfd"
date: "2018-01-27T21:51:14Z"
tags: ["PHP"]
categories: ["互联网"]
slug: "mylog"
draft: false
lastmod: "2018-01-27T21:51:13Z"
id: 2409338
url: "https://lxmgfd.iteye.com/blog/2409338"
---

```php


<?php 
function mylog($word = '',$var=array(), $log_name='Log', $log_path=ROOT_PATH."data/log/") 
{
	
	$output = "----------------------------------------------------------------------------------------------------\n";
	
	$output .= strftime("%Y%m%d %H:%M:%S", time()) . "    " ;
	$output .= $word."\n" ;
	if(!empty($var)){
		$output .= print_r($var, true)."\n";
	}
	$output.="\n";

	if(!is_dir($log_path)){
		@mkdir($log_path, 0777, true);
	}
	
	file_put_contents($log_path . $log_name . "_".strftime("%Y%m%d", time()).".txt", $output, FILE_APPEND | LOCK_EX);
}


?>


```


在项目中引入mylog.php， 即可使用。使用方式：

```php
echolog(数据源,'文件名','文件路径');
```



如有不足之处， 欢迎留言指导