Code Monkey home page Code Monkey logo

laravel-log-viewer's Introduction

Laravel log viewer

Packagist Packagist Packagist Scrutinizer Code Quality Author

TL;DR

Log Viewer for Laravel 5, 6, 7, 8, 9 & 10 (still compatible with 4.2 too) and Lumen. Install with composer, create a route to LogViewerController. No public assets, no vendor routes, works with and/or without log rotate. Inspired by Micheal Mand's Laravel 4 log viewer (works only with laravel 4.1)

What ?

Small log viewer for laravel. Looks like this:

capture d ecran 2014-12-01 a 10 37 18

Install (Laravel)

Install via composer

composer require rap2hpoutre/laravel-log-viewer

Add Service Provider to config/app.php in providers section

Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class,

Add a route in your web routes file:

Route::get('logs', [\Rap2hpoutre\LaravelLogViewer\LogViewerController::class, 'index']);

Go to http://myapp/logs or some other route

Install (Lumen)

Install via composer

composer require rap2hpoutre/laravel-log-viewer

Add the following in bootstrap/app.php:

$app->register(\Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class);

Explicitly set the namespace in app/Http/routes.php:

$router->group(['namespace' => '\Rap2hpoutre\LaravelLogViewer'], function() use ($router) {
    $router->get('logs', 'LogViewerController@index');
});

Advanced usage

Customize view

Publish log.blade.php into /resources/views/vendor/laravel-log-viewer/ for view customization:

php artisan vendor:publish \
  --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" \
  --tag=views

Edit configuration

Publish logviewer.php configuration file into /config/ for configuration customization:

php artisan vendor:publish \
  --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider"

Troubleshooting

If you got a InvalidArgumentException in FileViewFinder.php error, it may be a problem with config caching. Double check installation, then run php artisan config:clear.

laravel-log-viewer's People

Contributors

agontuk avatar anthonyporthouse avatar apreiml avatar cino avatar djoeycl avatar djunehor avatar donportugal avatar elminson avatar ghobaty avatar imanghafoori1 avatar limonte avatar mattlibera avatar mikemand avatar okaufmann avatar qwici avatar raazpuspa avatar rafaelbeckel avatar rap2hpoutre avatar rtconner avatar sarahman avatar scrutinizer-auto-fixer avatar sdapkus avatar sergiy-petrov avatar solinx avatar sskl avatar susanbuck avatar thdaguin avatar timothymarois avatar tmdh avatar xembill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-log-viewer's Issues

Method [all] does not exist.

I am getting the above Error.

I placed the Class LaravelLogViewer to App/Backend

<?php

namespace App\Http\Controllers\Backend;


use Illuminate\Support\Facades\View;

class LaravelLogViewer extends \Illuminate\Routing\Controller
{
    public function index()
    {
        if (\Input::get('l')) {
            LaravelLogViewer::setFile(base64_decode(\Input::get('l')));
        }
        $logs = LaravelLogViewer::all();
        View::addNamespace('laravel-log-viewer', __DIR__.'/../views');
        return View::make('laravel-log-viewer::log', [
            'logs' => $logs,
            'files' => LaravelLogViewer::getFiles(true),
            'current_file' => LaravelLogViewer::getFileName()
        ]);
    }
}

My Route:

Route::get('logs', 'Backend\LaravelLogViewer@index');

Do i need to add any ServiceProvider or something like this ?

Could we disable auto refresh

This feature is completely freezing up my browser every time when I have alot of data. until this becomes a setting could you give me a pointer as to where to disable it in the code?

Lumen compatibility

I get Class App\Http\Controllers\\Rap2hpoutre\LaravelLogViewer\LogViewerController does not exist when using this with Lumen

feature suggestion

I often get errors in view files. Such as this one:
storage/framework/views/43b5cdd1d840a31e686df15ac113ab92:45.

It would be just great to be able to click the filename and see the content - and match the line with blade file
or at least somehow get the filename of the original blade file.

Now I am forced to

  • get the cached view file,
  • open it locally
  • identify the right blade file
  • find the corresponding line in the blade file
  • fix it
    70% of debugging time goes to the procedure of locating the problematic spot.

Great repo, BTW!!
Thx

log level emergency not exists

Hello,

It seems that the log level 'emergency' not exists.

ErrorException in LaravelLogViewer.php line 104:
Undefined index: emergency

Lumen 5.3 Redirect not implemented

we need to fix the controller b/c Redirect is not working

clicking delete gives:

"message": "Class redirect does not exist",
"exception": "ReflectionException",

cheers max

[Proposal] Show additional information in sidebar?

Hi, I have just discovered this package and love it. I was wondering what you'd think about adding additional information on rollover on links in the sidebar? I think the file size and the number of entries would be two valuable informations to have without having to click and load the file.

[idea] Clickable row

When looking at errors I think it would be easier to make the complete row or at least the error itself clickable instead of just the magnifier glass on the right.
Reason is because I'm too lazy to move the mouse to the right every time, do others agree with this?

Exceprion if log folder is empty

exception 'ErrorException' with message 'preg_match_all() expects parameter 2 to be string, array given'
in /var/www/html/app/public/vendor/rap2hpoutre/laravel-log-viewer/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php:73

Thank you. (y)

Request: Split view into layout + content

After the suggestion here:

#39 (comment)

The idea is to have separate views - one for the layout, i.e. the page wrapper, and one for the content - the tables. Anyone wanting to put the content into their own layout templates in their own application, will need to split the view like this as the first step, so it will help a lot to build it like this in the first place.

External layout

It would be great to have config file with ability to use own layout file and integrate it seamlessly in backend application.

Unable to open log viewer due to lack of memory

production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 153967073 bytes)' in /srv/www/someline.com/someline/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:34

I think the problem is underlying that the log files are large in size, if you load them all in one time, it will not able to display.

Could you advice some solutions?

Request: Reduce white space in the tables

This log viewer will be viewing some massive files, which thousands of entries. The table that is rendered has thousands of rows, and many more table cells.

All this is padded out with white space from the view, which can add megabytes to a page, and contribute to the browser crashing. Can this white space between elements, and around data in table cells, be stripped out? I'm not sure how to suggest this is done, while preserving the readability of the source view, but there must be a way.

Update README

The command composer require rap2hpoutre/laravel-log-viewer should be used in place of composer require rap2hpoutre/laravel-log-viewer:0.2.* as the former will resolve to the lastest stable version with any patch version e.g. composer require rap2hpoutre/laravel-log-viewer:~0.2

This will save having to update the README's installation instructions on every new release.

Converting context to human readable

The second argument for Log::info() (or any other log) takes the context array. Would you be able to manage to implement a more human readable form instead of a json representation of the array?

I currently add a new line to my message so it drops the context to a new line. This way it will be caught by $log['stack'] and expanded when the search button is pressed.

Needs HTML Encoding in place

Needs htmlentities() (or similar) wrapped around at least the output of $log['stack']... otherwise "bad things" happen... :-)

Proposal: show emails in html format

It would be very useful to see the rendered html message in log when we are debugging e-mail workflow using "log" driver.

I've managed to do that modifying log.blade.php @line 87 to be like this:

@if(!strpos($log['stack'],'Content-Transfer-Encoding'))
    <div class="stack" id="stack{{{$key}}}" style="display: none; white-space: pre-wrap;">{{{ trim( $log['stack'] ) }}}</div>
@else
    <div class="stack" id="stack{{{$key}}}" style="display: none;">{!! preg_replace('/(Content-Transfer-Encoding[^\n]+)/', '$1<br><br>', $log['stack']) !!}</div>
@endif

It basically detects the last mail header and prints the unescaped html message, if the log entry is an e-mail.

It's a dirty hack and needs some cleanup, but worked pretty well for me. ;)

May I submit a PR?

Support for changing blade delimiters

I change blade's default delimiters in my laravel project, like so:

/*-------------------------------------------------------------------------
| Change default Blade delimiters
|------------------------------------------------------------------------*/
Blade::setContentTags('[[', ']]');              // for variables and all things Blade
Blade::setEscapedContentTags('[[#', '#]]');     // for escaped data

Which makes Laravel Log viewer not play well, I have to go and edit the views in the source to change all the delimiters.

Any way you can add a feature that detects what the current delimiters are and use those for the log view?

use custom view

how can i use custom view ? Because these cdns that used in your view is so slow in my country (china), and i want to change direction and font-family to make my logs looks nicer (arabic letters).

Use overflow:auto container for stack trace element

Sometimes the log/stacktrace is pretty wide, and when I expand it, I cannot collapse it without scrolling sideways, because the button moves out of the visible area (and it's on a 1920px wide screen)
Screenshot

I suggest wrapping the stack trace in a separate element and overflow:auto it, so the main layout doesn't expand more than needed.

Customizing views

Hello, good morning.

After trying a few different methods I found a way to make the package use my own View, adding this to routes.php in Laravel 4.2

\View::addNamespace('laravel-log-viewer', app_path().'/views/packages/laravel-log-viewer/');

I think it should be appropriate to add this information to Readme, I don't dare because I'm not sure this is the 100% best method.

Thanks.

[Insight] Unused use statement should be avoided - in src/controllers/LogViewerController.php, line 7

in src/controllers/LogViewerController.php, line 7

The class Illuminate\Support\Facades\Input is declared but never used. You should remove the use statement.

namespace Rap2hpoutre\LaravelLogViewer;

use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;

Posted from SensioLabsInsight

Why was a service provider added?

You don't need to register your own views namespace. Just use this in your controller:

    return View::file(__DIR__.'/../views/log.blade.php', [...]);

If the reason it was added is to support L4, I have to disagree. Taylor has said many times that if you need to support L4 and L5, they should live in separate branches.

Adding a service provider complicates this package for no reason. You usually don't want this in production, so I loaded this package in composer's require-dev array, and have this in my routes file:

if (config('app.debug'))
{
    get('logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index');
}

There's no reason you should now have to conditionally load a service provider.

error

hi,
i get this error how can i fix this?
InvalidArgumentException in FileViewFinder.php line 112: No hint path defined for [laravel-log-viewer].

thanks

Allow to download log files

Sometimes it's easier to view log file a notepad, for searching, etc. Maybe it would be useful, if I could download a log file with a click :)

What do you think about this feature?

Permission Denied

Getting this:
ErrorException in Filesystem.php line 109:
file_put_contents(/8414948cc128b33a8c074d83101ba69d62cc89a5.php): failed to open stream: Permission denied

/storage/logs/laravel.log has 777 permissions.

Any idea?

Thanks.

What about extra fields? preg_match() it to extra index?

Now we have a preg_match() that extract all things to $current array

preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);

with this results

$log[] = array(
    'level' => $level_value,
    'level_class' => self::$levels_classes[$level_value],
    'level_img' => self::$levels_imgs[$level_value],
    'date' => $current[1],
    'text' => $current[2],
    'in_file' => isset($current[4]) ? $current[4] : null,
    'stack' => preg_replace("/^\n*/", '', $log_data[$i])
);

And all okay, but if i adding processors:

// processor, adding URI, IP address etc. to the log
$monolog->pushProcessor(new Monolog\Processor\WebProcessor);
// processor, memory usage
$monolog->pushProcessor(new Monolog\Processor\MemoryUsageProcessor);

In our log we now have two new items in message ex:

Logger message! [] {"memory_usage":"19,25 MB","url":"/it/dashboard/clients/clients","ip":"95.254.111.11","http_method":"GET","server":"www.server.com","referrer":null,"unique_id":"Vzs4x1BYW8cBBEH123gAAABL"} 

What if we add something to preg_match() for capture log extra and take it separately?

ex:

  preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level_key . ': (.*?) ( in .*?:[0-9]+)?  (\{.*\}?)$/', $h[$i], $current);

I tryed but need help from someone more expert than me.
Log message with stack trace are different?
How put an optional reg_exp in case if trace/in_file are not present?

If this thing are interesting i can investigate and make a pr.

Read errors from DB

Hi, I use this code to save all errors to DB. Maybe create reader for that ?

Log::listen(function($level, $message, $context) {
$apiName = php_sapi_name();
$date = new DateTime;
Queue::push(function() use ($level, $message, $context, $apiName, $date) {
DB::insert("INSERT INTO logs (php_sapi_name, level, message, context, created_at) VALUES (?, ?, ?, ?, ?)", array(
            $apiName,
            $level,
            $message,
            json_encode($context),
            $date
        ));
    });
});

ServiceProvider not found

Hi !

I use laravel 4.2
I have this error message when i want going on the log page
Class 'Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class' not found

thx !

Request: Add support for seeing context

Some times I find it useful to set a custom context when logging and it'd be awesome to see this shown in the table.

When I do this it allows me to see where particular logging is coming form in my apps, I know it's not something that everyone may think is essential but to me this would be a great help. I believe it should be pretty darn easy to get setup too.

I think I'll submit a patch for this later tonight if I'm able to get it working.

Can't find the controller class. Maybe namespace error?

Hi,

When I add the code Route::get('logs', 'Rap2hpoutre\LaravelLogViewer\LogViewerController@index'); to routes.php, and then visit http://myapp/logs , it shows

Class App\Http\Controllers\Rap2hpoutre\LaravelLogViewer\LogViewerController does not exist

How can I fix it? Thanks!

Lumen install not working

Hello,

Thanks for writing such a great tool. I'm trying to install it on Lumen and I'm running into issues. When I run ..

composer require rap2hpoutre/laravel-log-viewer

.. a rap2hpoutre folder is added to my vendor folder. And attempting to access the controller throws an error:

ReflectionException in Container.php line 749: Class App\Http\Controllers\Rap2hpoutre\LaravelLogViewer\LogViewerController does not exist

Any help would be much appreciated.

Memory error for big log file

I have a very big (2,5GB) log file in my Laravel application because it used a single log file in the past. I've installed the package, but I'm getting a memory exhausted error.
[2015-03-23 09:08:50] live.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 2658702094 bytes)'

Instruction not working for Lumen 5.3

Got this error after following the installation instruction for Lumen:
Class App\Http\Controllers\Rap2hpoutre\LaravelLogViewer\LogViewerController does not exist

FYI, the route's settings file in Lumen 5.3 is on: routes/web.php

Empty logs rather than delete

It's a great feature to delete logs you no longer need, but for log files that will be recreated (Such as lumen.log or laravel.log), wouldn't it be best to just empty it?

Live Stream Log

It would be awesome if the page would automatically update when there are new items to show.

Ideally, this would be done with sockets. I don't have a lot of experience with sockets in PHP, but I've found it's not nearly as easy as say, Node and socket.io.

I'm really not sure how viable this is in pure PHP (i.e. I don't know that you can really watch for file changes in realtime with PHP), but it would be a super useful feature! Definitely possible and not terrible difficult with Node, but that'd require another dependency.

Just wanted to throw this out there and see if anyone else had any ideas.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.