From 57edc98b126645e2f3beb3d222c2194f4a436fe1 Mon Sep 17 00:00:00 2001 From: velz Date: Sat, 27 Apr 2019 15:52:37 +0530 Subject: [PATCH] REQ LOG ENBALED --- .../helpers/authorization_helper.php | 3 + api/application/helpers/mylog_helper.php | 24 +- .../language/english/message_lang.php | 1 + api/application/libraries/REST_Controller.php | 19 ++ .../request_logs/ssa_app_2019-04-27.html | 205 ++++++++++++++++++ 5 files changed, 243 insertions(+), 9 deletions(-) create mode 100644 api/application/request_logs/ssa_app_2019-04-27.html diff --git a/api/application/helpers/authorization_helper.php b/api/application/helpers/authorization_helper.php index 92f955d7..5e4481de 100644 --- a/api/application/helpers/authorization_helper.php +++ b/api/application/helpers/authorization_helper.php @@ -25,6 +25,7 @@ class AUTHORIZATION set_status_header(REST_CONTROLLER::HTTP_UNAUTHORIZED,"Unauthorized"); $response['status']=false; $response['error']="Invalid token!"; + log_message('error','Invalid token!'); echo json_encode($response); exit; } @@ -33,6 +34,7 @@ class AUTHORIZATION set_status_header(REST_CONTROLLER::HTTP_UNAUTHORIZED,"Unauthorized"); $response['status'] = false; $response['message'] = 'Token Experied'; + log_message('error','Token Experied'); echo json_encode($response); exit; @@ -66,6 +68,7 @@ class AUTHORIZATION set_status_header(REST_CONTROLLER::HTTP_UNAUTHORIZED,"Unauthorized"); $response['status']=false; $response['error']="Access denied!"; + log_message('error','Access denied!'); echo json_encode($response); exit; } diff --git a/api/application/helpers/mylog_helper.php b/api/application/helpers/mylog_helper.php index faf240d9..98468e38 100644 --- a/api/application/helpers/mylog_helper.php +++ b/api/application/helpers/mylog_helper.php @@ -6,20 +6,26 @@ class MYLOG // Create the logger - public static function logFunction() //$msg,$data,$log_type + public static function logFunction($dynamic = null) //$msg,$data,$log_type { + $channel = $dynamic ? $dynamic : 'ssa_beta_logger'; + $log_folder = $dynamic ? 'request_logs' : 'syslogs'; include_once APPPATH.'/vendor/autoload.php'; - $logger = new \Monolog\Logger('ssa_beta_logger'); - $streamHandler = new \Monolog\Handler\StreamHandler(APPPATH.'syslogs/ssa_app_'.date('Y-m-d').'.html', $logger::DEBUG); + $logger = new \Monolog\Logger($channel); + $streamHandler = new \Monolog\Handler\StreamHandler(APPPATH.$log_folder.'/ssa_app_'.date('Y-m-d').'.html', $logger::DEBUG); $streamHandler->setFormatter(new \Monolog\Formatter\HtmlFormatter()); $browserHanlder = new \Monolog\Handler\BrowserConsoleHandler($logger); $logger->pushProcessor(new \Monolog\Processor\WebProcessor()); - $logger->pushProcessor(new \Monolog\Processor\IntrospectionProcessor()); - $logger->pushProcessor(new \Monolog\Processor\ProcessIdProcessor()); - $logger->pushProcessor(new \Monolog\Processor\UidProcessor()); - //$logger->pushProcessor(new \Monolog\Processor\HostnameProcessor()); - $logger->pushProcessor(new \Monolog\Processor\MemoryUsageProcessor()); - $logger->pushProcessor(new \Monolog\Processor\MemoryPeakUsageProcessor()); + + if(!$dynamic) + { + $logger->pushProcessor(new \Monolog\Processor\IntrospectionProcessor()); + $logger->pushProcessor(new \Monolog\Processor\ProcessIdProcessor()); + $logger->pushProcessor(new \Monolog\Processor\UidProcessor()); + //$logger->pushProcessor(new \Monolog\Processor\HostnameProcessor()); + $logger->pushProcessor(new \Monolog\Processor\MemoryUsageProcessor()); + $logger->pushProcessor(new \Monolog\Processor\MemoryPeakUsageProcessor()); + } $logger->pushHandler($streamHandler); return $logger; diff --git a/api/application/language/english/message_lang.php b/api/application/language/english/message_lang.php index b3d9bbc7..67c94a57 100644 --- a/api/application/language/english/message_lang.php +++ b/api/application/language/english/message_lang.php @@ -1 +1,2 @@ \ No newline at end of file diff --git a/api/application/libraries/REST_Controller.php b/api/application/libraries/REST_Controller.php index 488e5bb7..7021fb4e 100644 --- a/api/application/libraries/REST_Controller.php +++ b/api/application/libraries/REST_Controller.php @@ -366,6 +366,25 @@ abstract class REST_Controller extends CI_Controller { */ protected function early_checks() { + $this->load->library('user_agent'); + if ($this->agent->is_browser()) + { + $agent = $this->agent->browser().' '.$this->agent->version(); + } + elseif ($this->agent->is_robot()) + { + $agent = $this->agent->robot(); + } + elseif ($this->agent->is_mobile()) + { + $agent = $this->agent->mobile(); + } + else + { + $agent = 'Unidentified User Agent'; + } + $logger = MYLOG::logFunction('request_logger'); + $logger->info('REQUEST_INFO',array('ip' => $this->input->ip_address(),'paltform' => $this->agent->platform(),'browser' => $agent)); } /** diff --git a/api/application/request_logs/ssa_app_2019-04-27.html b/api/application/request_logs/ssa_app_2019-04-27.html new file mode 100644 index 00000000..fce0777a --- /dev/null +++ b/api/application/request_logs/ssa_app_2019-04-27.html @@ -0,0 +1,205 @@ +

INFO

+ + + + + + + + + + + + + + +
Message:
REQUEST_INFO
Time:
2019-04-27 15:34:34
Channel:
request_logger
Context: + + + + + + + + +
ip:
::1
paltform:
Windows 10
browser:
Firefox 66.0
Extra: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
memory_peak_usage:
3.25 MB
memory_usage:
3.25 MB
uid:
f4965c2
process_id:
10204
file:
C:\5.6\xampp\htdocs\AWSEC2\sparqapi\api\application\libraries\REST_Controller.php
line:
387
class:
REST_Controller
function:
early_checks
url:
/AWSEC2/sparqapi/api/getUsersDetails
ip:
::1
http_method:
POST
server:
localhost
referrer:

INFO

+ + + + + + + + + + + + + + +
Message:
REQUEST_INFO
Time:
2019-04-27 15:38:18
Channel:
request_logger
Context: + + + + + + + + +
ip:
::1
paltform:
Windows 10
browser:
Firefox 66.0
Extra: + + + + + + + + + + + + + + + + + + + + + + + + + + +
file:
C:\5.6\xampp\htdocs\AWSEC2\sparqapi\api\application\libraries\REST_Controller.php
line:
387
class:
REST_Controller
function:
early_checks
url:
/AWSEC2/sparqapi/api/getUsersDetails
ip:
::1
http_method:
POST
server:
localhost
referrer:

INFO

+ + + + + + + + + + + + + + +
Message:
REQUEST_INFO
Time:
2019-04-27 15:38:22
Channel:
request_logger
Context: + + + + + + + + +
ip:
::1
paltform:
Windows 10
browser:
Firefox 66.0
Extra: + + + + + + + + + + + + + + + + + + + + + + + + + + +
file:
C:\5.6\xampp\htdocs\AWSEC2\sparqapi\api\application\libraries\REST_Controller.php
line:
387
class:
REST_Controller
function:
early_checks
url:
/AWSEC2/sparqapi/api/getUsersDetails
ip:
::1
http_method:
POST
server:
localhost
referrer:

INFO

+ + + + + + + + + + + + + + +
Message:
REQUEST_INFO
Time:
2019-04-27 15:39:12
Channel:
request_logger
Context: + + + + + + + + +
ip:
::1
paltform:
Windows 10
browser:
Firefox 66.0
Extra: + + + + + + + + + + + + + + +
url:
/AWSEC2/sparqapi/api/getUsersDetails
ip:
::1
http_method:
POST
server:
localhost
referrer:
\ No newline at end of file