How to View Remote CodeIgniter Log Files in the Browser and Postman


In this article, we're going to look at how to access the log files of a CodeIgniter application via a web browser or Postman (API calls). This is a follow-up article to this first article that I published on medium.

Being able to easily read log files on a live server is a vital tool in a developer's toolbox. It can boost the quality of emergency readiness and response.

We'll be achieving our aim with the help of the codeigniter-log-viewer library. It can be installed, via composer, by simply running:

composer require seunmatt/codeigniter-log-viewer 

This post assumes you have a deployed CodeIgniter project with log files that you want to access.

Viewing Log Files in the Browser

Following the installation of the library, we need to create a controller that will be mapped to a route on our web application. Let's call the controller LogViewerController.php.

In the controller, let's instantiate the CILogViewer class and make use of it in the index() function: 

private $logViewer;

public function __construct() {
    $this->logViewer = new \CILogViewer\CILogViewer();

public function index() {
    echo $this->logViewer->showLogs();

Finally, we're going to map the controller function to a route by adding the following entries to application/config/routes.php

$route['logs'] = "logViewerController/index";

Please note that the /logs route should be protected. That's it! A visit to /logs on our application will produce a view like this: 


From the view, it's possible to delete the current log file or all the log files. You can also download the log file to your local system. Note that if the file is too large for displaying, you'll have to download it locally for viewing.

Now, let's get to an even more interesting part!

Viewing the Log files in Postman

So with v1.1.0 of codeigniter-log-viewer, we can actually make API calls to access our logs remotely. The controller set up is just the same as above. 

How is this possible? It is, because the library uses query parameters as commands that are interpreted internally to provide appropriate JSON response.

To get all the log files that are available, we need to make an API call to this endpoint via Postman or other API clients:


 This will return a JSON response containing the list of log files:

    "status": true,
    "log_files": [
            "file_b64": "bG9nLTIwMTgtMDgtMjQucGhw",
            "file_name": "log-2018-08-24.php"
            "file_b64": "bG9nLTIwMTgtMDgtMjMucGhw",
            "file_name": "log-2018-08-23.php"

Furthermore, to view the content of a log file, we need to make a call this endpoint:


The name of the file is obtained from the previous call and is set as the value of the f parameter (f stands for file).

This will return a JSON response containing the logs as an array and a list of available log files as well:

    "log_files": [
            "file_b64": "bG9nLTIwMTgtMDEtMTkucGhw",
            "file_name": "log-2018-01-19.php"
            "file_b64": "bG9nLTIwMTgtMDEtMTcucGhw",
            "file_name": "log-2018-01-17.php"
    "status": true,
    "logs": [
        "ERROR - 2018-01-23 07:12:31 --> 404 Page Not Found: admin/Logs/index",
        "ERROR - 2018-01-23 07:12:37 --> 404 Page Not Found: admin//index",
        "ERROR - 2018-01-23 15:23:02 --> 404 Page Not Found: Faviconico/index"

 We can delete a single log file by calling this endpoint:


 or this endpoint to delete all the log files:




Now, that we've seen how good the library is and what it can offer. It's time to incorporate it into our existing projects and give it a star on Github.

More Technology Stories