Message12624

Author jeff.allen
Recipients jeff.allen
Date 2019-08-07.08:33:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565166794.43.0.20360063213.issue2778@roundup.psfhosted.org>
In-reply-to
Content
I think I've a satisfactory approach to this now.

PS jython-trunk> dist\bin\jython -vv -S
org.python: (FINE) initializer: 'META-INF/services/org.python.core.JythonInitializer' not found on sun.misc.Launcher$AppClassLoader@49aa95c
org.python: (FINE) initializer: 'META-INF/services/org.python.core.JythonInitializer' not found on sun.misc.Launcher$AppClassLoader@49aa95c
org.python: (FINE) *sys-package-mgr*: reading cache, 'C:\Users\Jeff\Documents\Eclipse\jython-trunk\dist\jython-dev.jar'
...
org.python: (FINE) threadstate: no current system state
org.python: (FINE) import: trying org.python.core.exceptions as builtin modules in SysPathJavaLoader
org.python: (CONFIG) import: 'exceptions' as org.python.core.exceptions in builtin modules
Jython 2.7.2a1+ (default:011472a1af03+, Aug 7 2019, 08:31:05)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_80
<file-top>:
>>> from org.python.core import Py, Options
<single-top>: Py= Options=
org.python: (FINE) import: trying org in packagemanager for path None
...
org.python: (CONFIG) import: 'Options' as java class
>>> Py.getLoggingLevel()
<single-top>: Py
org.python: (FINE) import: trying precompiled C:\Users\Jeff\Documents\Eclipse\jython-trunk\dist\Lib\encodings\__init__$py.class
...
FINE
>>> Options.verbose
<single-top>: Options
3

Although Options.verbose is now deprecated in favour of setting a logging level, it actually works quite well for code that continues to use the legacy methods.

>>> Options.verbose = 1
<single-top>: Options
>>> Py.writeMessage("hello", "world")
org.python: (INFO) hello: world
>>> Py.getLoggingLevel()
INFO
>>> from java.util.logging import Level
>>> Py.setLoggingLevel(Level.CONFIG)
>>> Options.verbose
2
>>> Py.writeComment("hello", "world")
org.python: (CONFIG) hello: world
>>> Py.writeDebug("hello", "world")


However there is a slight wrinkle where a security manager is in force. The best response I can think of is to complain and continue, but it means we don't get to control the  verbosity:

PS jython-trunk> dist\bin\jython -v "-J-Djava.security.manager" "-J-Djava.security.policy=Lib\test\python_home.policy"
org.python: (WARNING) unable to configure console messages: access denied ("java.util.logging.LoggingPermission" "control")
org.python: (WARNING) A security manager prevented a change to the logging level.
Jython 2.7.2a1+ (default:011472a1af03+, Aug 7 2019, 08:31:05)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_80
Type "help", "copyright", "credits" or "license" for more information.
>>> from org.python.core import Py, Options
>>> Py.writeMessage("hello", "world")
org.python: (INFO) hello: world
>>> Py.writeComment("hello", "world")        # this should come out (because of the -v)
>>> Options.verbose                          # this should be 2 (also because of the -v)
1
>>> Options.verbose = 4                      # you can set it
>>> Py.writeComment("hello", "world")        # and we try to transfer it to a logging level
<single-top>: Py
org.python: (WARNING) A security manager prevented a change to the logging level.
>>> Options.verbose                          # it gets reset consistent with the logging.
1
History
Date User Action Args
2019-08-07 08:33:14jeff.allensetmessageid: <1565166794.43.0.20360063213.issue2778@roundup.psfhosted.org>
2019-08-07 08:33:14jeff.allensetrecipients: + jeff.allen
2019-08-07 08:33:14jeff.allenlinkissue2778 messages
2019-08-07 08:33:14jeff.allencreate