Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ideolog (PyCharm): how to configure log format for standard logging library

I am using standard Python logging library (import logging) and install Ideolog plugin. But it doesn't support format of standard logging library (and PyCharm asks to configure it). I have tried some regex, but they don't fit. How should I configure it?

Screen of log format and Ideolog error

Default Ideolog settings

PS In code I use logging like logging.info('Some info')

like image 258
Abionics Avatar asked Jun 23 '19 12:06

Abionics


2 Answers

if you don't want to struggle much with regular expressions you can do an easy one

(INFO)

will match "INFO" and you can do the rest for the other levels for a quick visualization.

like image 162
pelos Avatar answered Sep 20 '22 19:09

pelos


Had an issue on a very short test file - only four entries - and was searching forever why my correct pattern was not applied.

As the official docs state here https://github.com/JetBrains/ideolog/wiki/Custom-Log-Formats

Selecting the right pattern

"In order to detect the format of a log file, all existing patterns are matched against first 25 lines of a file. The one with most matches gets selected, if the amount of matches is above 5. Otherwise, a dumb per-line parser is used."

So if your log file is below 5 entries, the algorithm says it can not detect the correct pattern - and does not apply any pattern, even if there is only one active pattern and the regex works 100% fine.

Groups

"In addition, you must specify capture group indices for time, severity and category. Capture groups are numbered starting with 1. If you don't have a capture group for an item, specify 0."

Hence: Group Numbering starts at 1 !

My config

str_logging_format = "%(asctime)s - %(name)-12s - %(levelname)-8s - %(message)s"

# -- Ideolog Config --
# :pattern:
# ^(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s-\s(\S*)\s*-\s(\w*)\s*-\s(.*)$
# :timePattern: yyyy-MM-dd HH:mm:ss,SSS
# :linePattern: ^\d
# :time Group : 1
# :severity Group : 3
# :Category Group: 2
#
# :highlighting:
# pattern="^\s*CRITICAL\s*$" action="HIGHLIGHT_LINE" fg="FF0000" bold="true" stripe="true"
# pattern="^\s*ERROR\s*$" action="HIGHLIGHT_LINE" fg="FF5F62" stripe="true"
# pattern="^\s*WARNING\s*$" action="HIGHLIGHT_LINE" fg="C73EC8" bold="true"
# pattern="^\s*INFO\s*$" action="HIGHLIGHT_LINE" fg="08C8EA"
# pattern="^\s*DEBUG\s*$" action="HIGHLIGHT_LINE" fg="3940C8"

PS: https://regex101.com/ is awesome to test your pattern.

like image 35
Red Avatar answered Sep 20 '22 19:09

Red