Lightsquid Stop Working in 2021
Lightsquid is a handy log analyzer for squid proxy. However, the project is not maintained since 2009.
Today, I found lightsquid doesn’t work in 2021. Why?
Lightsquid Error
When I run lightparser, the output looks like this:
| |
Seems that all lines are filtered by the date filter. I double checked the log format and make sure it is correct and the same with previous days.
Analyze the Problem
Look at this piece of code (I am a Perl layman): here
| |
Found two issues:
- A hardcode
2020in$filterdatestopwhich makes lightsquid not work in 2021 todayargument cannot work with customized file at the same time
First Issue
Obviously, $filterdatestop is the culprit:
| |
A quick fix is to change the hardcoded 2020 to 2100. It seems that the month and year parameter are weird…
I read the document of Perl’s “Time::Local” and found that the design is really complex and hard to understand (personally I think it is anti-pattern, why not make it a simple design which supports only absolute year?):
- Years greater than 999 are interpreted as being the actual year, rather than the offset from 1900. Thus, 1964 would indicate the year Martin Luther King won the Nobel prize, not the year 3864.
- Years in the range 100..999 are interpreted as offset from 1900, so that 112 indicates 2012. This rule also applies to years less than zero (but see note below regarding date range).
- Years in the range 0..99 are interpreted as shorthand for years in the rolling “current century,” defined as 50 years on either side of the current year. Thus, today, in 1999, 0 would refer to 2000, and 45 to 2045, but 55 would refer to 1955. Twenty years from now, 55 would instead refer to 2055. This is messy, but matches the way people currently think about two digit dates. Whenever possible, use an absolute four digit year instead.
Then I try to understand what these lines means:
Output:
The solution is easy, change this line to(note that the month is zero indexed (0..11)), and now it works until 2100:
| |
Second Issue
Another problem is that today argument cannot work with customized filename:
| |
Apparently, only one argument ARGV[0] is applied. If you wrote the command like this and not fixed the first issue:
| |
or
| |
You will encounter the “parsed 0 lines” error.
Summary
Just fix the first issue and you will make lightsquid works longer :-)
| |
Fixed version: https://github.com/finisky/lightsquid-1.8.1