Convert Gitlab Raw Log into HTML Using PHP

This tutorial help to convert gitlab raw log into html color view. The gitlab ci/cd are generating logs for each jobs. You can view color view logs using gitlab view.

I have asked question into the as well, but did not get answer from any body So I have shared my solution that can be helpful.

Use case :-

I am creating a angularjs ui where user can see gitlab job logs, So we have created a rest call that ll return raw logs as text and render into html UI.

How to get logs using API

The gitlab v4 api is providing a rest end point to get a log (trace) of a specific job of a project.

GET /projects/:id/jobs/:job_id/trace

Where id is the project id and job_id is the job id.

I have created a Laravel api that will return html format of raw git job logs, I have taken this job logs but in git raw api there is ANSI codes that need to convert into HTML5 format.

The trace url would be –

When we access above api call, We ll get the raw logs with ansi characters, that ll hold color value;

I am using laravel 7 framework, so i ll use sensiolabs/ansi-to-html package that help to convert ANSI character into html.

Let’s install packages –
composer require sensiolabs/ansi-to-html

Convert Gitlab Raw into HTML

We have installed package into the application, open the testController.php file and added below code into the top of the file –

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;

Created the instance into the controller constructor method :

Let’s call convert method over the gitlab raw logs.

When you render above response into html file, You will get below view –

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.