Welcome Guest, Not a member yet? Register   Sign In
How do I view error logs?
#1

[eluser]snifty[/eluser]
I have a logs directory under application in my app, and it contains a couple files, which look like this:

Code:
$ cat log-2011-06-14.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

DEBUG - 2011-06-14 03:35:26 --> Config Class Initialized
DEBUG - 2011-06-14 03:35:26 --> Hooks Class Initialized
DEBUG - 2011-06-14 03:35:26 --> Utf8 Class Initialized

...snip..., etc etc, depending on the error level in my config.php

My question is, what is the "right" way to view these files? they're clearly not PHP files, so I don't understand why they're assigned a .php filetype and that "No direct script" restriction. Is the idea that error logs should only be viewed through a terminal?

I will read Logging.php and try to figure out the reasoning here, but I thought I'd ask the question as well.

Thanks folks...
#2

[eluser]InsiteFX[/eluser]
Just click on the filenames, they are saved as normal text files so your default text editor should just load them up!

InsiteFX
#3

[eluser]TWP Marketing[/eluser]
I think (opinion), that the script access restriction is a simplistic way to prevent anyone but the programmer/administrator from viewing the log files. The logs might give insight into how a program is designed and/or contain information which might be used to hack a database.

If you WANT the admins to see the logs, just build a view and hide it behind the admin login.
#4

[eluser]John_Betong_002[/eluser]
The post prompted me to stop procrastinating and to add the facility of log file viewing and deletion if and only if on your http://localhost/
 


Five steps to view your log file in a popup window:
 
 

step 1. include this line in your views:   ./application/view/view_main_or_whatever_it_is_called.php
Code:
<body>
  <?php if('localhost' === $_SERVER['SERVER_NAME']) { include '_box_view_errors.php'; } ?>
* above script displays a link to a popup view error log file if and only if errors log file exists.
 
 
 
 
step 2. add these lines to:     ./application/config/routes.php
Code:
$route["popup_view_errors"]        = "c_view_errors";
$route["popup_view_errors/(:any)"] = "c_view_errors/$1";
* above script is routed from the "View errors" button to the NEW controller file.
 
 
 
step 3. NEW Controller file:     ./application/controllers/c_view_errors.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// file save as  ./application/controllers/c_view_errors.php

//========================================
class c_view_errors extends CI_Controller
{

private $atts = array(
              'width'      => '800',
              'height'     => '600',
              'scrollbars' => 'yes',
              'status'     => 'yes',
              'resizable'  => 'yes',
              'screenx'    => '123',
              'screeny'    => '42'
            );
            
//===================================================
public function index($tmp=NULL)
{
  $data['view_errors'] =  anchor_popup('popup_view_errors', 'View errors', $this->atts);
  
  $this->load->view('view_pop_errors');
  
}//endfunc


//===================================================
function delete_log_file()
{
  $ff = $this->config->item('log_path') .'log-' .date('Y-m-d') .'.php';

  // delete file
  if(file_exists($ff) && unlink($ff))
  {
    $this->load->view('view_pop_errors');
  }else{
    echo heading('Big problem :( <br />' .__FILE__);
  }
}


}//endclass
* controller script to call the popup view error page or to delete the error log file
&nbsp;
&nbsp;
&nbsp;



step 4. NEW file: &nbsp; &nbsp; ./application/views/_box_view_errors.php
Code:
&lt;?php
  $ff = $this->config->item('log_path')  .'log-' .date('Y-m-d')  .'.php';
  
  // if and only if file exists
  if(file_exists($ff) && filesize($ff))
  {
?&gt;
  <h1 style='float:left; background-color:#fc9; border:solid 5px #b90'>
    <a   title="email a friend.">
      View errors
    </a>
  </h1>
  <br style='clear:left' />
&lt;?php } ?&gt;
* view script to show link button if and only if error_log_file exists
&nbsp;
&nbsp;
&nbsp;



step 5. NEW Popup View file: &nbsp; &nbsp; ./application/views/_box_view_errors.php
Code:
&lt;?php /* file: ./application/views/_box_view_errors.php */ ?&gt;
<!doctype html>
&lt;head&gt;
&lt;title&gt;View errors&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  <div>
    &lt;?php
      $ff = $this->config->item('log_path') .'log-' .date('Y-m-d') .'.php';
      
      if (file_exists($ff))
      {
        // get file in a string
        $ff = highlight_file($ff, TRUE);
    
        // cosmetic
        $ff = str_replace('ERROR', '<br />Error<br />', $ff);
        
        // show errors
        echo $ff;
  
        // maybe delete
        echo '<p>' .anchor('popup_view_errors/delete_log_file', 'Delete log file') .'</p>';
      }else{
        // notification
        echo heading('It' gone: '. $ff,4);
      }
    ?&gt;

    &lt;?php /* include('_java_close_window.php'); */ ?&gt;
    &lt;input
      id='close'
      style='background:#f90 none; color:#00f;'
      type='button' value="Close Window"&gt;
  </div>
&lt;/body&gt;&lt;/html>
* the popup view error log file.
&nbsp;
&nbsp;
&nbsp;


edit
Replaced correct controller file.
Renamed popup view file.
Added button link script
&nbsp;
&nbsp;
&nbsp;
#5

[eluser]snifty[/eluser]
Hi John,

This looks like a useful way to view logs. What's _box_view_errors.php all about?
#6

[eluser]John_Betong_002[/eluser]
[quote author="snifty" date="1308801498"]Hi John,

This looks like a useful way to view logs. What's _box_view_errors.php all about?[/quote]

Whoops, I renamed "_box_view_errors.php" and did not change the old file name. My post has just been edited and now shows the correct file name and the include file name.

Here is a partial screen dump when the "View errors" link is called.

http://johns-jokes.com/afiles/images/c-_...g-file.jpg
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB