DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • A Step-By-Step Guide: How To Install a Laravel Script
  • Maximizing Laravel's Potential: A Guide to Driver-Based Services
  • Speed Up Your Laravel Website With Performance Optimization Tips
  • DGS GraphQL and Spring Boot

Trending

  • A Guide to Developing Large Language Models Part 1: Pretraining
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • Unlocking the Benefits of a Private API in AWS API Gateway
  1. DZone
  2. Coding
  3. Frameworks
  4. A Five Minute Solution for Viewing Logs in a Laravel Application

A Five Minute Solution for Viewing Logs in a Laravel Application

Skip the ssh, view logs directly in your Laravel application.

By 
Adi Sk user avatar
Adi Sk
·
Sep. 10, 19 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
13.0K Views

Join the DZone community and get the full member experience.

Join For Free

logs-stacked-on-one-another

Hi all, it’s been a few months since my last Laravel-related post. So, I decided to write something small to get back into the rhythm of things. I plan to publish something every month or even more frequently.

We have all been there — your Laravel app isn’t working as expected, and you want to get to logs as fast as possible. In most situations we may not have easy access to log files because we need an ssh client to connect to the server, then navigate to the logs, and finally view the last entry in there. It’s always a pain in the neck to do this. In this post, I want to show you my simple solution to viewing logs from within the app. I implemented this on a recent client project and it works quite well.

You may also like: A Complete Guide to Laravel 5.8 Installation.

As always, if you have a better implementation, please share, I would love to know about it.

Overview

Here’s an overview of my solution. I have a route to a page, whose controller reads that day’s log file and sends it to the view. The view has two parts; it has a form to change the date of the currently viewed file and a section where the logs are shown.

Pretty simple aye? If it was not clear enough, check the code below.

Code

First off, add a route where you want to display the log file entries
Route file content

Route file content

Then comes the controller. Below is the logic for the controller. Here, we get the date for when we need the logs for. Then, we extract information about the file and its contents and send it to the view.

Controller file contents

Controller file contents

Here, in the view, we have two parts — one to change the date of the Log file and the other to view the actual Log file’s contents.
View file contents

View file contents

Once you put everything together, you will have your own Log Viewer. The image below is what I have after adding some CSS. Not bad for like five minutes of work.
Final result

Final result

Conclusion

I hope this solution is of some use to you. If you have a better solution to do the same, do let them know. I am more than glad to try it.

Related resources

  • https://laravel.com/docs/6.0/errors.
  • https://github.com/rap2hpoutre/laravel-log-viewer.
  • https://github.com/ARCANEDEV/LogViewer.

That’s all for now. Talk to you in the next one.


Related Articles

  • PHP Monolog Tutorial: A Step-by-Step Guide.
Laravel application

Published at DZone with permission of Adi Sk. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • A Step-By-Step Guide: How To Install a Laravel Script
  • Maximizing Laravel's Potential: A Guide to Driver-Based Services
  • Speed Up Your Laravel Website With Performance Optimization Tips
  • DGS GraphQL and Spring Boot

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!