Class jython
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default format for console log messages in the command-line Jython. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidEvents from within the Jython implementation are surfaced through thejava.util.logging.Loggerorg.pythonor a child of it.static voidMostly reverse the effects ofloggingToConsole(), by removing from the "org.python" logger the handler that prints to the console, and setting the "org.python" logger to propagate records to its parent handlers.static voidMain Jython program, following the structure and logic of CPythonmain.cto produce the same behaviour.static voidDeprecated.static intRuns a JAR file, by executing the code found in the file __run__.py, which should be in the root of the JAR archive.
-
Field Details
-
CONSOLE_LOG_FORMAT
The default format for console log messages in the command-line Jython. Seejava.util.logging.SimpleFormatterfor an explanation of the syntax.This format is used in the absence of other logging preferences, and only if property
python.logging.defaultis not defined. Jython tests for definitions in the system properties ofjava.util.logging.config.class,java.util.logging.config.file, andjava.util.logging.SimpleFormatter.formatand if none of these is defined, it sets the last of them to this value.You can choose something else, for example to log with millisecond time stamps, launch Jython as:
jython -vv -J-Djava.util.logging.SimpleFormatter.format="[%1$tT.%1$tL] %3$s: (%4$s) %5$s%n"
Depending on your shell, the argument may need quoting or escaping.- See Also:
-
-
Constructor Details
-
jython
public jython()
-
-
Method Details
-
loggingToConsole
public static void loggingToConsole()Events from within the Jython implementation are surfaced through thejava.util.logging.Loggerorg.pythonor a child of it. When Jython is used interactively, we normally want these to emerge on the console, in a succinct form, not via the java.util.logging root logger. This method is called bymain(String[])to achieve that.The root logger format is hard to read for humans. The logging level of the handler defaults to
INFO, and does not respond to the-voption. (It could be made to, but then all logging would be be turned up together.) This method makes these adjustments to logging:- The format
SimpleFormatteris replaced with a simpler format (but only if no other logging customisation is present). (Affects all logging.) - A console handler is installed for logger
org.pythonusing that aSimpleFormatterand accepts all levels. - Logger
org.pythonis told not to propagate records to parent handlers (so that messages are not emitted twice.
org.pythonand its child loggers by default, which determines admission of logging, reflects the "verbosity" set by the `-v` option. - The format
-
loggingToDefault
public static void loggingToDefault()Mostly reverse the effects ofloggingToConsole(), by removing from the "org.python" logger the handler that prints to the console, and setting the "org.python" logger to propagate records to its parent handlers. The method does not try to reset the propertyjava.util.logging.SimpleFormatter.format, which is in any case only read during static initialisation bySimpleFormatter. -
runJar
Runs a JAR file, by executing the code found in the file __run__.py, which should be in the root of the JAR archive. Note that__name__is set to the base name of the JAR file and not to "__main__" (for historical reasons). This method does not handle exceptions. the caller should handle any(Py)Exceptionsthrown by the code.- Parameters:
filename- The path to the filename to run.- Returns:
0on normal termination (otherwise throwsPyException).
-
run
Deprecated.Now equivalent tomain(String[]), which is to be preferred. -
main
Main Jython program, following the structure and logic of CPythonmain.cto produce the same behaviour. The argument to the method is the argument list supplied after the class name in thejavacommand. Arguments up to the executable script name are options for Jython; arguments after the executable script are supplied insys.argv. "Executable script" here means a Python source file name, a module name (following the-moption), a literal command (following the-coption), or a JAR file name (following the-jaroption). As a special case of the file name, "-" is allowed, meaning take the script from standard input.The main difference for the caller stems from a difference between C and Java: in C, the argument list
(argv)begins with the program name, while in Java all elements of(args)are arguments to the program.- Parameters:
args- arguments to the program.
-