Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a level filter #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,12 @@ public function getFiles($basename = false, $folder = '')
}
return array_values($files);
}

/**
* @return Level
*/
public function getLevel()
{
return $this->level;
}
}
1 change: 1 addition & 0 deletions src/controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function index()
'files' => $this->log_viewer->getFiles(true),
'current_file' => $this->log_viewer->getFileName(),
'standardFormat' => true,
'levels' => $this->log_viewer->getLevel()->all(),
];

if ($this->request->wantsJson()) {
Expand Down
71 changes: 60 additions & 11 deletions src/views/log.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
}

#table-log {
font-size: 0.85rem;
font-size: 0.85rem;
}

.sidebar {
font-size: 0.85rem;
line-height: 1;
font-size: 0.85rem;
line-height: 1;
}

.btn {
font-size: 0.7rem;
font-size: 0.7rem;
}

.stack {
Expand Down Expand Up @@ -62,10 +62,21 @@
height: 80vh;
overflow: hidden auto;
}

.nowrap {
white-space: nowrap;
}

.level svg {
margin-right: 5px;
}

.level-select select {
display: inline-block;
margin-left: 5px;
width: auto;
}

</style>
</head>
<body>
Expand Down Expand Up @@ -125,7 +136,7 @@ class="list-group-item @if ($current_file == $file) llv-active @endif">
<tr data-display="stack{{{$key}}}">
@if ($standardFormat)
<td class="nowrap text-{{{$log['level_class']}}}">
<span class="fa fa-{{{$log['level_img']}}}" aria-hidden="true"></span>&nbsp;&nbsp;{{$log['level']}}
<span class="fa fa-{{{$log['level_img']}}}" aria-hidden="true"></span>{{$log['level']}}
</td>
<td class="text">{{$log['context']}}</td>
@endif
Expand Down Expand Up @@ -195,8 +206,9 @@ class="float-right expand btn btn-outline-dark btn-sm mb-2 ml-2"
$('.table-container tr').on('click', function () {
$('#' + $(this).data('display')).toggle();
});
$('#table-log').DataTable({
"order": [$('#table-log').data('orderingIndex'), 'desc'],

var options = {
"order": [$("#table-log").data("orderingIndex"), "desc"],
"stateSave": true,
"stateSaveCallback": function (settings, data) {
window.localStorage.setItem("datatable", JSON.stringify(data));
Expand All @@ -205,11 +217,48 @@ class="float-right expand btn btn-outline-dark btn-sm mb-2 ml-2"
var data = JSON.parse(window.localStorage.getItem("datatable"));
if (data) data.start = 0;
return data;
}
});
$('#delete-log, #clean-log, #delete-all-log').click(function () {
return confirm('Are you sure?');
},
};

@if ($standardFormat)
options.dom = "<'row'<'col-sm-4'l><'level-select col-sm-4'><'col-sm-4'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-5'i><'col-sm-7'p>>";
@endif

var table = $("#table-log").DataTable(options);

$("#delete-log, #clean-log, #delete-all-log").click(function () {
return confirm("Are you sure?");
});

{{-- Add a level select filter --}}
@if ($standardFormat)
var levels = @json($levels);

var logSelect = "<label>Level " +
"<select id=\"level\" class=\"form-control form-control-sm\">" +
"<option value=\"\">all</option>";

for (var i = 0; i < levels.length; i++) {
logSelect += "<option value=\"" + levels[i] + "\">" + levels[i] + "</option>";
}

logSelect += "</select></label>";

$("div.level-select").html(logSelect);

// Redraw the table whenever the level select changes
$("#level").change(function () {
table.draw();
});

$.fn.dataTable.ext.search.push(
function (settings, data) {
var level = $("#level").val();

return !level || data[0] === level;
},
);
@endif
});
</script>
</body>
Expand Down