scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.56k stars 467 forks source link

Adding `DEBUG_INFO` setting #560

Open noviluni opened 5 years ago

noviluni commented 5 years ago

I was thinking about how to improve the "debugging" process when weird things happen...

And I realized that it could be really useful to add an option to "see" what happens behind the scenes. It could be, for example, a setting called DEBUG_INFO that when True shows relevant information to help you to understand what's happening.

I was trying a little and that's what I got.


Input:

dateparser.parse('07/03/2009')

Log:

Interpretation: 07 - 03 - 2009
Order: month, day, year
Used locale: en

Out:

2009-07-03 00:00:00

Input:

dateparser.parse('2009')

Log:

Missing: Day, Month
Interpretation: 2009
Order: year
Used locale: en

Out:

2009-09-05 00:00:00

Input:

dateparser.parse('Feb 2009')

Log:

Missing: Day
Interpretation: february - 2009
Order: year
Used locale: en

Out:

2009-02-05 00:00:00

Input:

dateparser.parse('07/03/2009', locales=['fr'])

Log:

Interpretation: 07 - 03 - 2009
Order: day, month, year
Used locale: fr

Out:

2009-03-07 00:00:00

Input:

dateparser.parse('en 2 días')

Log:

Used locale: es

Out:

2019-09-07 17:46:02.653798

Of course there are a lot of new information that could appear in the log, that's just an idea.

What do you think?

noviluni commented 5 years ago

I just added a draft PR with the code I used to get the log in the examples.

noviluni commented 5 years ago

It could help in some situations like this: https://github.com/scrapinghub/dateparser/issues/520#issuecomment-489556731

noviluni commented 4 years ago

I expect to continue with this PR after merging this: https://github.com/scrapinghub/dateparser/pull/603 as it would be a good starting point :)

noviluni commented 4 years ago

Related to this: https://github.com/scrapinghub/dateparser/pull/729