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

import pyrevit.coreutils mutes my logger #575

Closed
amastrobera opened this issue Apr 12, 2019 · 2 comments
Closed

import pyrevit.coreutils mutes my logger #575

amastrobera opened this issue Apr 12, 2019 · 2 comments

Comments

@amastrobera
Copy link

amastrobera commented Apr 12, 2019

Hello Ehsan,

I have a pushbutton from which I log activity with

import logging, logging.config
conf = logging.config.fileConfig(...) 
logger = logging.getLogger("angelo")
... 
logger.info(...) # I am logging to file 
...

I wanted not to display the terminal window that pops out at execution. So I did this

from pyrevit.coreutils.loadertypes import ScriptOutputManager
ScriptOutputManager.CloseActiveOutputWindows()

Despite this line does the trick, import pyrevit.coreutils ... somehow diverts my logs, and nothing is written to the file. Do you know how I can not display the cmd window without muting my logs?

Thank you


FYI but not necessary, the fileConfig contains this. Logs are also muted if I decide to use the root logger with logger = logging.getLogger() or if I choose my own screen logging logger = logging.getLogger("angeloscreen") or if I use the stderr instead of stdout.

[loggers]
keys=root,angelo,angeloscreen
                   
[logger_root]
qualname=root     
handlers=null                      
level=NOTSET
                   
[logger_angelo]                                                                        
qualname=angelo
handlers=file
level=DEBUG

[logger_angeloscreen]                                                                        
qualname=angeloscreen
handlers=screen
level=DEBUG

[formatters]
keys=simple

[formatter_simple]
format= %(levelname)s - %(message)s

[handlers]
keys=null,file,screen

[handler_null]
class=NullHandler
args=()

[handler_file]
class=FileHandler
formatter=simple
level=DEBUG
args=('execution.log', 'w')

[handler_screen]
class=StreamHandler
formatter=simple
level=DEBUG
args=(sys.stdout,)
@eirannejad
Copy link
Collaborator

Give me a little more info on what you are trying to do. The startup log message is controlled through Settings tool. I'm not sure why you are manually reaching inside the API to close the windows with ScriptOutputManager.CloseActiveOutputWindows()

I'm thinking the issue is that you want everything in pyrevit to be silent ("No Reporting" under settings) but the info messages from your tool to be printed still?

@eirannejad
Copy link
Collaborator

pyRevit shared the same logging module with all the scripts and sets it up extensively in coreutils.logger. You need to setup your own logging configs in your script

import os.path as op
import logging
#pylint: disable=import-error,invalid-name,broad-except
from pyrevit import USER_SYS_TEMP
from pyrevit import coreutils
from pyrevit import script


slogger = script.get_logger()


# create own logger
LOG_REC_FORMAT_FILE = "%(asctime)s %(levelname)s: [%(name)s] %(message)s"
LOG_FILEPATH = op.join(USER_SYS_TEMP, 'indeplog.log')
file_hndlr = logging.FileHandler(LOG_FILEPATH, mode='a')
file_formatter = logging.Formatter(LOG_REC_FORMAT_FILE)
file_hndlr.setFormatter(file_formatter)
logger = logging.getLogger('MyIndependentLogger')    # type: LoggerWrapper
logger.addHandler(file_hndlr)

slogger.info('logget type: %s', type(slogger))
slogger.critical('testing CRITICAL')
slogger.error('testing ERROR')
slogger.warning('testing WARNING')
slogger.info('testing INFO')
slogger.debug('testing DEBUG')


logger.info('logget type: %s', type(logger))
logger.critical('testing CRITICAL')
logger.error('testing ERROR')
logger.warning('testing WARNING')
logger.info('testing INFO')
logger.debug('testing DEBUG')


coreutils.show_entry_in_explorer(LOG_FILEPATH)

del logger

Tested this on v4.6.24 dev branch and works. The independent script logger logs independently from the pyRevit provided slogger logger.

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

No branches or pull requests

2 participants