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 script for log viewer #1042

Closed

Conversation

YevhenZvieriev
Copy link
Contributor

@YevhenZvieriev YevhenZvieriev commented Jan 14, 2024

Pull Request Description

Summary

This pull request adds a script designed for managing and analyzing Magento 2 logs. The script provides functionality to view existing log files, display the content of specific log files, and search for errors in log files.

  • Added a script (bin/log) to the project for Magento 2 log management.
  • Implemented functions for viewing log files, displaying specific log content, searching for errors, tail logs in real-time, and configuring options.
  • Improved formatting and color-coding for better readability.

Usage Instructions

  1. Choose an option to view existing log files, display specific log content, and search for errors or to tail logs in real-time.
  2. Follow the prompts to input your choice and necessary details.
  3. The script interacts with Docker to access log files within a Magento 2 container.

Screenshots

  1. log-tracker-1

  2. log-tracker-2

  3. log-tracker-3

Updated 09.02.2024

Add the possibility to tail logs in real-time

Video how the script works:

script.log.video.mp4

Updated 10.02.2024

Changes made

  1. Delete duplicate code

  2. Add the possibility to tail all error logs in real time

  3. Add the possibility to execute bin/log with arguments

For example bin/log --tail cron.log system.log OR bin/log -t system.log cron.log to shorten

To avoid mixing, I did it as follows:

First, the logs from the first file are displayed, then after Ctrl + C you can see the real-time logs from the second file

  1. Given the length of the script, I've provided comments to help people understand if they would like to contribute.

How works added features:

script.log.video.webm

Updated 15.02.2024

Add the possibility to configure options (log path and container name)

Hello friends, this functionality will be useful for those with log files stored in a folder other than the default, so you can change it to suit your needs. Also, for your convenience, if you don't want to change the path or container name, press Enter to keep the current value

How works added feature:

script.log.options.webm

P.S. I'm also going to develop the ability to view logs in a certain date range, would this be useful to you?

Feel free to provide feedback or suggestions for improvement.

Copy link

what-the-diff bot commented Jan 14, 2024

PR Summary

  • Addition of compose/bin/log File
    The new file introduced is a script which allows users to view, search through and monitor, in real-time, logs generated by our systems. It adds a user-friendly interactivity by providing a menu for easy navigation and control.

compose/bin/log Outdated Show resolved Hide resolved
@bbakalov
Copy link
Contributor

I've tested this script. And have some thoughs about features that could be added.

For example:

  1. Tail all error logs.
  2. Some arguments for quick run action, for example:
    bin/log -t (or --tail) and optional name of the log to tail OR in case if log file not provided grep all
    bin/log -t system.log cache.log

Also on macos error viewer not correctly show error names. Maybe on ubuntu doesn't have this problem
telegram-cloud-photo-size-2-5348081792692900753-y

@YevhenZvieriev
Copy link
Contributor Author

YevhenZvieriev commented Feb 10, 2024

Good idea, @bbakalov!

Hold my beer, buddy)

The problem you describe is related to the fact that macOS uses a different color scheme for managing text color than Ubuntu or other Linux systems. I tried to fix it, can you check now?

@bbakalov
Copy link
Contributor

The problem you describe is related to the fact that macOS uses a different color scheme for managing text color than Ubuntu or other Linux systems. I tried to fix it, can you check now?

Adding \b \b/ fixing color problem

# Function to format log output with colors
function format_log_output() {
    sed -E 's/(ERROR|FATAL|CRITICAL)/\o033[31m\1\o033[0m/g' | sed -E 's/\bWARNING\b/\o033[33m&\o033[0m/g' | sed -E 's/\bINFO\b/\o033[32m&\o033[0m/g' | sed -E 's/\bDEBUG\b/\o033[36m&\o033[0m/g'
}

@bbakalov
Copy link
Contributor

bbakalov commented Feb 10, 2024

2. Add the possibility to tail all error logs in real time

I've tested it, but haven't found this possibility

BTW during testing tail by file, I found interesting behaviour.
telegram-cloud-photo-size-2-5350333592506585736-y
First, it shows an exception log, then i click crtl+c, displays system.log, and so on.

It's not call to action for changes =) Just what I've found)

@YevhenZvieriev
Copy link
Contributor Author

Adding \b \b/ fixing color problem

I don't have a Mac to check this, I added it to the prior commit. Hopefully, this will be helpful.

  1. Add the possibility to tail all error logs in real time

I've tested it, but haven't found this possibility

Perhaps I described the functionality incorrectly, and you are confused.

I added the ability to tail all error logs in real-time in the selected file.

Run bin/log, then choose option 4, then option 2 (View only error logs in real-time), where you can select the name of the log file you wish to examine.

Screenshot from 2024-02-10 21-41-54

I've tested it, but haven't found this possibility

BTW during testing tail by file, I found interesting behaviour.

Yes, I know, I pointed it out here:

To avoid mixing, I did it as follows:

First, the logs from the first file are displayed, then after Ctrl + C you can see the real-time logs from the second file

This is not "interesting behavior", this was done on purpose to avoid mixing logs from different files.

BTW, feel free to contribute :)

@markshust
Copy link
Owner

Thank you, I appreciate this PR and the updates made.

However, the first run-through of this script didn't go well for me. Here is the output:

~/Sites/magento-admingridforms bin/log
Developed by Yevhen Zvieriev

Choose an option:
1. View existing log files
2. Display the content of a specific log file
3. Search for errors in log files
4. Tail logs in real-time
5. Configure options
Enter the option number (1, 2, 3, 4 or 5): 4

Choose an option:
1. View all logs in real-time
2. View only error logs in real-time
Enter the option number (1 or 2): 1

Choose a log file to tail:

Available log files:
1. debug.log
2. system.log
3. exception.log
Enter the log file name (with extension, e.g., system.log): 
Press [Ctrl+C] to stop tailing logs

Tailing logs from ...
tail: error reading '/var/www/html/var/log/': Is a directory
tail: /var/www/html/var/log/: cannot follow end of this type of file; giving up on this name
tail: no files remaining
Press [Enter] to return to the menu
Continue (Y/n)? y

Choose an option:
1. View existing log files
2. Display the content of a specific log file
3. Search for errors in log files
4. Tail logs in real-time
5. Configure options
Enter the option number (1, 2, 3, 4 or 5): 1

Available log files:
1. debug.log
2. system.log
3. exception.log
Continue (Y/n)? 1

Choose an option:
1. View existing log files
2. Display the content of a specific log file
3. Search for errors in log files
4. Tail logs in real-time
5. Configure options
Enter the option number (1, 2, 3, 4 or 5): 2

Available log files:
1. debug.log
2. system.log
3. exception.log
Enter the log file name (with extension, e.g., system.log):
  1. In the first attempt, I chose 1 for the 1. View all logs in real-time option. Then, it prompted me for the file. I would expect it to immediately show the logs after entering 1.

  2. Secondly, I was asked:

Available log files:
1. debug.log
2. system.log
3. exception.log
Continue (Y/n)? 1

The Y/n prompt is very confusing, because I was expecting to enter a 1, 2, or 3 to designate the type of file that I'd like tailed.

  1. For the last prompt:
Choose an option:
1. View existing log files
2. Display the content of a specific log file
3. Search for errors in log files
4. Tail logs in real-time
5. Configure options
Enter the option number (1, 2, 3, 4 or 5): 2

Available log files:
1. debug.log
2. system.log
3. exception.log
Enter the log file name (with extension, e.g., system.log):

I was presented with yet another permutation. I wasn't asked 1, 2, or 3, or for a Y/n, but rather the name of the log file.

I think if you are running with the numbered list, the prompts should ALWAYS be 1, 2, 3, etc., never a Y/n, and never the name of a file. It's extremely confusing otherwise.

I was also randomly presented with:

Press [Enter] to return to the menu
Continue (Y/n)? y

I don't know what I'm supposed to do. Type enter? Then the Continue Y/n prompt... what am I continuing to? What happens when I type Y? What happens when I type N? I'm very confused. The script has potential but the UX needs a lot of work.

@markshust
Copy link
Owner

Closing in favor of #1060

@markshust markshust closed this Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants