Commit ae14f02f by BANice

日志类完善,未添加一次性写入全部日志

parent e9cf0ed4
......@@ -48,8 +48,6 @@ class AccessController extends Controller
if ($gatewayId != false) {
echo 'bind mac - '.$mac.PHP_EOL;
//tcp绑定uid
Gateway::bindUid($this->clientId, $mac);
......
......@@ -10,6 +10,7 @@ namespace Application\Controller;
use Application\Controller;
use Application\Model\OrderModel;
class PowerController extends Controller
{
......@@ -39,6 +40,9 @@ class PowerController extends Controller
];
/**
* 硬件开始充电
*/
public function charger()
{
......@@ -50,6 +54,13 @@ class PowerController extends Controller
$outTradeNo = $this->get('outTradeNo');
//fixme 修改订单表中,订单的状态位
$orderModel = new OrderModel();
$row = $orderModel->update(['state' => 1],'out_trade_no = '.$outTradeNo);
var_dump($row);
}
......@@ -59,6 +70,9 @@ class PowerController extends Controller
}
/**
* 硬件充电结束
*/
public function stop()
{
......@@ -78,6 +92,9 @@ class PowerController extends Controller
}
/**
* 上报充电功率
*/
public function power()
{
......
......@@ -12,6 +12,7 @@ use Lib\Crc;
use GatewayWorker\Lib\Gateway;
use Route\Api;
use Lib\Route;
use Lib\Log;
define('APP','Application\\Controller\\');
......@@ -60,11 +61,22 @@ class Events
}
public static function onConnect($clientId)
{
Log::debug('connect',[
'time' => date('H:i:s')
]);
}
public static function onMessage($clientId,$message)
{
//$message = mb_strtoupper($message);
var_dump($message);
......@@ -78,6 +90,7 @@ class Events
}else{
$command = substr($message,6,2);
var_dump($command);
......@@ -91,12 +104,13 @@ class Events
$method = $route->getMethod();
$controllerName = APP.$controllerName;
//去除crc字节
$message = substr($message,0,-2);
$message = mb_strtoupper($message);
$controller = new $controllerName($clientId,$message,$command);
$controller->$method();
......
......@@ -73,6 +73,11 @@ class Model
}
/**
* @param $where
* @return array
*/
public function getRow($where)
{
......@@ -80,6 +85,10 @@ class Model
}
/**
* @param array $data
* @return mixed
*/
public function insertRow(Array $data)
{
return $this->db->insert($this->table)->cols($data)->query();
......@@ -87,6 +96,18 @@ class Model
}
/**
* @param array $update
* @param $where
* @return mixed
*/
public function update(array $update ,$where)
{
return $this->db->update($this->table)->cols($update)->where($where)->query();
}
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/5/22
* Time: 下午2:53
*/
namespace Application\Model;
use Application\Model;
class OrderModel extends Model
{
protected $table = 'wx_charger_order';
}
\ No newline at end of file
......@@ -15,10 +15,9 @@ use Monolog\Logger;
/**
*
* @method static debug($info,$context = [])
* @method static warn($info,$context = [])
* @method static alert($info,$context = [])
* @method static error($info,$context = [])
* @method static warn($info, $context = [])
* @method static alert($info, $context = [])
* @method static error($info, $context = [])
*
* Class Log
* @package Lib
......@@ -34,33 +33,27 @@ class Log
private function __construct(string $logName)
{
$this->log = new Logger($logName);
$this->log->pushHandler(new RotatingFileHandler($logName,30,Env::get('LOG_LEVEL')));
$this->log->pushProcessor(function ($record){
$record['extra']['gateway_mac'] = S_SESSION['gateway_mac'] ?? 'no mac';
});
}
public static function bootLog(string $logName = 'error')
public static function bootLog(string $logName = './storage/log/gateway')
{
if(static::$log instanceof Log)
{
if (static::$log instanceof Log) {
return static::$log;
}else{
} else {
static::$log = new Log($logName);
static::$log = new Logger($logName);
static::$log->pushHandler(new RotatingFileHandler($logName, 30, Env::get('LOG_LEVEL')));
// static::$log->pushProcessor(function ($record) {
//
// $record['extra']['gateway_mac'] = S_SESSION['gateway_mac'] ?? 'no mac';
//
// });
}
}
......@@ -72,7 +65,7 @@ class Log
public static function __callStatic($name, $arguments)
{
static::$log->$name($arguments);
return call_user_func_array([static::$log,$name],$arguments);
}
......
......@@ -31,7 +31,7 @@ function exceptionHandle($exception)
{
$logger = new \Monolog\Logger('error');
$logger->pushHandler(new \Monolog\Handler\RotatingFileHandler('./storage/error', 30));
$logger->pushHandler(new \Monolog\Handler\RotatingFileHandler('./storage/log/error', 30));
try{
$logger->error($exception->getMessage(),[
......@@ -65,9 +65,11 @@ foreach (glob(__DIR__ . '/Application/start*.php') as $start_file) {
}
}
require_once $start_file;
//require_once $start_file;
}
\Lib\Log::bootLog();
\Route\Api::boot();
Worker::runAll();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment