hide logging lines

for PyCharm the best and awesomest IDE ever!!!! :D :') ;)

Hi,

since i used nearly 10 hours to find a solution to my problem (and i read all suggested post while i give my post a title) i want to ask this question here plain in to the crowd:

i working on a rather complex problem, that's why i have to do a lot of logging (which i do whit a own logging module) it logs on level 0: status: every initialisation of an class, or everything else i account for very important, 1 for error... and so on, you can picture it ;)

well... it clutters my code and it is a real mess!!! it is ugly and i hate it!!!

ALL OF THIS LINES BEGINS WITH: logger.log(.....)

so i wonder... there must be a possibility to hide all lines that begins with some remarkable, some every same token.....

i would like this hiding to switch it on or off!!!!

hide all lines that contents logger.log <> show all lines that contents logger.log

I saw code folding settings as well but they did not help in this particular matter :(

thanks in advance and best regards!!!

PS: i cant believe that i am the first person whit this problem....^^ so what is the solution??? please help!!!!

6 comments
Comment actions Permalink

Hi!

Is it sent to your console output or written to the log file?
If latter, then you could try Ideolog plugin https://plugins.jetbrains.com/plugin/9746-ideolog/

0
Comment actions Permalink

HI :)

finally an answer :D thanks for that!!! BUT....^^ :) ;)

it is not the output that troubles me!!! my logger can print to python console, or logfile, or both as well, it colours it, making usage of:

pip._vendor.colorama

witch i watch coloured as .txt using vim whit AnsiEsc.

what i am looking for is a add-on on or something that allows the following: (sorry for the red underlining^^)

class SuperImportant:
def __init__(self, data="important", make_super=True):
logger.log(0, f"{self.__class__.__name__} {lineNo()} --> initialisiert in SuperImportant")
self.data = data
self.make_super=make_super
logger.log(3, f"{Fore.MAGENTA}{self.__class__.__name__} {lineNo()} --> {Fore.RESET}"
f"self.data: {self.data}; self.make_super: {self.make_super}")

def makeSuperImportant(self):
logger.log(2, f"{Fore.YELLOW}{self.__class__.__name__} {lineNo()} --> {Fore.RESET}")
try:
self.iThinkYouGetThePoint()
except SuperImportantError as e:
logger.log(1, f"{Fore.RED}{self.__class__.__name__} {lineNo()} --> ERROR: {repr(e)}, {e.__cause__},{repr(e.__traceback__.tb_lineno)}{Fore.RESET}")
print(f"it is soooooo super-ugly {self.make_super}")

<toggle on> == -->

class SuperImportant:
def __init__(self, data="important", make_super=True):
self.data = data
self.make_super=make_super

def makeSuperImportant(self):
try:
self.iThinkYouGetThePoint()
except SuperImportantError as e:
print(f"it is soooooo super-ugly {self.make_super}")

and vice versa

best regards and thanks in advance!!!

2
Comment actions Permalink

I searched for this almost two years ago... and stopped doing it after not finding anything and thinking I was missing something that I had to learn. Not really. I'd really love this to be implemented. Is the number 1 thing I'm missing, as it is the one that makes me doing more not-really fruitful extra work...

When searching for bugs, sometimes we plague the code with logging.debug... It is nice that we can hide them from the results, but the code gets too plagued of not really meaningful stuff that we have to delete for production or for the rest of the team to work on it. But I'd like to keep it in case my later self or others, have to verify again what process the code is doing step by step. Many times it helps a lot to understand what the code is doing, more than comments and documentation itself. So it can be a lot of code, but one that it is only needed, or very useful, in certain situations, yet in others is the opposite to being useful and has to be removed. So a toggle on this would help us a lot!

I haven't been able to think or see any Pycharm (or any other IDE, which at least a year ago didn't have either) improvement more useful than this would be... 

1
Comment actions Permalink

I agree, this would be a great feature.

1
Comment actions Permalink

I found a way to do this that is a bit of a hack but has been working for me. In Pycharm's preferences Editor > General > Code Folding there is an option to enable 'Custom Folding Regions'. If that is toggled on in your code you can surround a block of text with a tag to allow you to fold that region. For example

# <editor-fold desc="logging">
logger.error("[log_tag:{}][isbn:{}] Validation of isbndb.com web service api return JSON of ISBN failed".format(log_tag, normalized_isbn))
logger.error("[log_tag:{}][isbn:{}] validation failure msg(b64): {}".format(log_tag, normalized_isbn, base64.b64encode(str(ve).encode('ascii'))))
logger.debug("[log_tag:{}][isbn:{}] validation failure msg: \n{}".format(log_tag, normalized_isbn, str(ve)))
# </editor-fold>

Will create a folding carrot in the left hand gutter that will fold the block to

logging

 

The name of the folded block comes from the value of the "desc" attribute in the surrounding tag.

 

It isn't a nice as the functionality in the original post's description but might be helpful.

2

Please sign in to leave a comment.