Package grails.build.logging
Class GrailsConsole
- java.lang.Object
-
- grails.build.logging.GrailsConsole
-
- All Implemented Interfaces:
ConsoleLogger
- Direct Known Subclasses:
GrailsEclipseConsole
public class GrailsConsole extends java.lang.Object implements ConsoleLogger
Utility class for delivering console output in a nicely formatted way.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCATEGORY_SEPARATORstatic java.lang.StringENABLE_INTERACTIVEstatic java.lang.StringENABLE_TERMINALstatic java.lang.StringERRORstatic java.lang.StringHISTORYFILEstatic java.lang.StringLINE_SEPARATORstatic java.lang.StringPROMPTstatic java.lang.CharacterSECURE_MASK_CHARstatic java.lang.StringSPACEstatic java.lang.StringSTACKTRACE_FILTERED_MESSAGEstatic java.lang.StringSTACKTRACE_MESSAGEstatic java.lang.StringWARNING
-
Constructor Summary
Constructors Modifier Constructor Description protectedGrailsConsole()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddShutdownHook()voidaddStatus(java.lang.String msg)Keeps doesn't replace the status messageprotected java.io.OutputStreamansiWrap(java.io.OutputStream out)Hook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream.voidappend(java.lang.String msg)voidbeforeShutdown()protected voidbindSystemOutAndErr(java.io.PrintStream systemOut, java.io.PrintStream systemErr)voidcleanlyExit(int status)protected jline.console.ConsoleReadercreateConsoleReader(java.io.InputStream systemIn)static GrailsConsolecreateInstance()protected jline.TerminalcreateTerminal()Creates the instance of Terminal used directly in GrailsConsole.voidechoStatus()Replays the last status messagevoiderror(java.lang.String msg)Prints an error messagevoiderror(java.lang.String label, java.lang.String message)Log an error with a specific error labelvoiderror(java.lang.String msg, java.lang.Throwable error)Use to log an errorvoiderror(java.lang.Throwable error)Use to log an errorvoidflush()Makes sure that the console has been reset to the default state and that the out stream has been flushed.java.util.Stack<java.lang.String>getCategory()java.lang.CharactergetDefaultInputMask()java.io.PrintStreamgetErr()java.io.InputStreamgetInput()static GrailsConsolegetInstance()java.lang.StringgetLastMessage()java.io.PrintStreamgetOut()jline.console.ConsoleReadergetReader()jline.TerminalgetTerminal()voidindicateProgress()Indicates progress with the default progress indicatorvoidindicateProgress(int number)Indicates progress by numbervoidindicateProgress(int number, int total)Indicate progress for a number and totalvoidindicateProgressPercentage(long number, long total)Indicates progress as a percentage for the given number and totalvoidinfo(java.lang.String msg)Synonym for #logprotected voidinitialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr)booleanisAnsiEnabled()booleanisInteractiveEnabled()booleanisStacktrace()booleanisVerbose()booleanisWindows()voidlog(java.lang.String msg)Logs a message below the current status messageprotected voidpersistHistory()protected jline.console.history.HistoryprepareHistory()Prepares a history file to be used by the ConsoleReader.protected voidredirectSystemOutAndErr(boolean force)voidreinitialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr)Use in testing when System.out, System.err or System.in changestatic voidremoveInstance()voidremoveShutdownHook()voidresetCompleters()voidrestoreOriginalSystemOutAndErr()protected voidrestoreTerminal()java.lang.StringsecureUserInput(java.lang.String msg)LikeuserInput(String)except that the user's entered characters will be replaced with '*' on the CLI, masking the input (i.e.voidsetAnsiEnabled(boolean ansiEnabled)voidsetDefaultInputMask(java.lang.Character defaultInputMask)voidsetErr(java.io.PrintStream err)static voidsetInstance(GrailsConsole newConsole)voidsetLastMessage(java.lang.String lastMessage)voidsetOut(java.io.PrintStream out)voidsetStacktrace(boolean stacktrace)voidsetVerbose(boolean verbose)java.lang.StringshowPrompt()Shows the prompt to request user inputvoidupdateStatus(java.lang.String msg)Updates the current state messagejava.lang.StringuserInput(java.lang.String msg)Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.java.lang.StringuserInput(java.lang.String message, java.lang.String[] validResponses)Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.java.lang.StringuserInput(java.lang.String message, java.util.List<java.lang.String> validResponses)voidverbose(java.lang.String msg)Outputs a verbose messagevoidwarn(java.lang.String msg)Prints a warn messagevoidwarning(java.lang.String msg)Prints an error message
-
-
-
Field Detail
-
ENABLE_TERMINAL
public static final java.lang.String ENABLE_TERMINAL
- See Also:
- Constant Field Values
-
ENABLE_INTERACTIVE
public static final java.lang.String ENABLE_INTERACTIVE
- See Also:
- Constant Field Values
-
LINE_SEPARATOR
public static final java.lang.String LINE_SEPARATOR
-
CATEGORY_SEPARATOR
public static final java.lang.String CATEGORY_SEPARATOR
- See Also:
- Constant Field Values
-
PROMPT
public static final java.lang.String PROMPT
- See Also:
- Constant Field Values
-
SPACE
public static final java.lang.String SPACE
- See Also:
- Constant Field Values
-
ERROR
public static final java.lang.String ERROR
- See Also:
- Constant Field Values
-
WARNING
public static final java.lang.String WARNING
- See Also:
- Constant Field Values
-
HISTORYFILE
public static final java.lang.String HISTORYFILE
- See Also:
- Constant Field Values
-
STACKTRACE_FILTERED_MESSAGE
public static final java.lang.String STACKTRACE_FILTERED_MESSAGE
- See Also:
- Constant Field Values
-
STACKTRACE_MESSAGE
public static final java.lang.String STACKTRACE_MESSAGE
- See Also:
- Constant Field Values
-
SECURE_MASK_CHAR
public static final java.lang.Character SECURE_MASK_CHAR
-
-
Method Detail
-
addShutdownHook
public void addShutdownHook()
-
removeShutdownHook
public void removeShutdownHook()
-
reinitialize
public void reinitialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr) throws java.io.IOExceptionUse in testing when System.out, System.err or System.in change- Throws:
java.io.IOException
-
initialize
protected void initialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr) throws java.io.IOException- Throws:
java.io.IOException
-
bindSystemOutAndErr
protected void bindSystemOutAndErr(java.io.PrintStream systemOut, java.io.PrintStream systemErr)
-
getErr
public java.io.PrintStream getErr()
-
setErr
public void setErr(java.io.PrintStream err)
-
setOut
public void setOut(java.io.PrintStream out)
-
isInteractiveEnabled
public boolean isInteractiveEnabled()
-
createConsoleReader
protected jline.console.ConsoleReader createConsoleReader(java.io.InputStream systemIn) throws java.io.IOException- Throws:
java.io.IOException
-
createTerminal
protected jline.Terminal createTerminal()
Creates the instance of Terminal used directly in GrailsConsole. Note that there is also another terminal instance created implicitly inside of ConsoleReader. That instance is controlled by the jline.terminal system property.
-
resetCompleters
public void resetCompleters()
-
prepareHistory
protected jline.console.history.History prepareHistory() throws java.io.IOExceptionPrepares a history file to be used by the ConsoleReader. This file will live in the home directory of the user.- Throws:
java.io.IOException
-
ansiWrap
protected java.io.OutputStream ansiWrap(java.io.OutputStream out)
Hook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream. Unfortunately, Eclipse consoles will look to the AnsiWrap like they do not understand ansi, even if we were to implement support in Eclipse to' handle it and the wrapped stream will not pass the ansi chars on to Eclipse).
-
isWindows
public boolean isWindows()
-
getInstance
public static GrailsConsole getInstance()
-
removeInstance
public static void removeInstance()
-
beforeShutdown
public void beforeShutdown()
-
restoreTerminal
protected void restoreTerminal()
-
persistHistory
protected void persistHistory()
-
setInstance
public static void setInstance(GrailsConsole newConsole)
-
redirectSystemOutAndErr
protected void redirectSystemOutAndErr(boolean force)
-
createInstance
public static GrailsConsole createInstance() throws java.io.IOException
- Throws:
java.io.IOException
-
setAnsiEnabled
public void setAnsiEnabled(boolean ansiEnabled)
-
setVerbose
public void setVerbose(boolean verbose)
- Parameters:
verbose- Sets whether verbose output should be used
-
setStacktrace
public void setStacktrace(boolean stacktrace)
- Parameters:
stacktrace- Sets whether to show stack traces on errors
-
isVerbose
public boolean isVerbose()
- Returns:
- Whether verbose output is being used
-
isStacktrace
public boolean isStacktrace()
- Returns:
- Whether to show stack traces
-
getInput
public java.io.InputStream getInput()
- Returns:
- The input stream being read from
-
getLastMessage
public java.lang.String getLastMessage()
- Returns:
- The last message logged
-
setLastMessage
public void setLastMessage(java.lang.String lastMessage)
-
getReader
public jline.console.ConsoleReader getReader()
-
getTerminal
public jline.Terminal getTerminal()
-
getOut
public java.io.PrintStream getOut()
-
getCategory
public java.util.Stack<java.lang.String> getCategory()
-
indicateProgress
public void indicateProgress()
Indicates progress with the default progress indicator- Specified by:
indicateProgressin interfaceConsoleLogger
-
indicateProgress
public void indicateProgress(int number, int total)Indicate progress for a number and total- Specified by:
indicateProgressin interfaceConsoleLogger- Parameters:
number- The current numbertotal- The total number
-
indicateProgressPercentage
public void indicateProgressPercentage(long number, long total)Indicates progress as a percentage for the given number and total- Specified by:
indicateProgressPercentagein interfaceConsoleLogger- Parameters:
number- The numbertotal- The total
-
indicateProgress
public void indicateProgress(int number)
Indicates progress by number- Specified by:
indicateProgressin interfaceConsoleLogger- Parameters:
number- The number
-
updateStatus
public void updateStatus(java.lang.String msg)
Updates the current state message- Specified by:
updateStatusin interfaceConsoleLogger- Parameters:
msg- The message
-
addStatus
public void addStatus(java.lang.String msg)
Keeps doesn't replace the status message- Specified by:
addStatusin interfaceConsoleLogger- Parameters:
msg- The message
-
error
public void error(java.lang.String msg)
Prints an error message- Specified by:
errorin interfaceConsoleLogger- Parameters:
msg- The error message
-
warning
public void warning(java.lang.String msg)
Prints an error message- Specified by:
warningin interfaceConsoleLogger- Parameters:
msg- The error message
-
warn
public void warn(java.lang.String msg)
Prints a warn message- Specified by:
warnin interfaceConsoleLogger- Parameters:
msg- The message
-
isAnsiEnabled
public boolean isAnsiEnabled()
-
error
public void error(java.lang.String msg, java.lang.Throwable error)Use to log an error- Specified by:
errorin interfaceConsoleLogger- Parameters:
msg- The messageerror- The error
-
error
public void error(java.lang.Throwable error)
Use to log an error- Specified by:
errorin interfaceConsoleLogger- Parameters:
error- The error
-
log
public void log(java.lang.String msg)
Logs a message below the current status message- Specified by:
login interfaceConsoleLogger- Parameters:
msg- The message to log
-
append
public void append(java.lang.String msg)
-
info
public void info(java.lang.String msg)
Synonym for #log- Specified by:
infoin interfaceConsoleLogger- Parameters:
msg- The message to log
-
verbose
public void verbose(java.lang.String msg)
Description copied from interface:ConsoleLoggerOutputs a verbose message- Specified by:
verbosein interfaceConsoleLogger- Parameters:
msg- The message
-
echoStatus
public void echoStatus()
Replays the last status message
-
userInput
public java.lang.String userInput(java.lang.String msg)
Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. Prints a message and returns whatever the user enters (once they press <return>).- Parameters:
msg- The message/question to display.- Returns:
- The line of text entered by the user. May be a blank string.
-
secureUserInput
public java.lang.String secureUserInput(java.lang.String msg)
LikeuserInput(String)except that the user's entered characters will be replaced with '*' on the CLI, masking the input (i.e. suitable for capturing passwords etc.).- Parameters:
msg- The message/question to display.- Returns:
- The line of text entered by the user. May be a blank string.
-
showPrompt
public java.lang.String showPrompt()
Shows the prompt to request user input- Returns:
- The user input prompt
-
userInput
public java.lang.String userInput(java.lang.String message, java.util.List<java.lang.String> validResponses)
-
userInput
public java.lang.String userInput(java.lang.String message, java.lang.String[] validResponses)Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. Prints a message and list of valid responses, then returns whatever the user enters (once they press <return>). If the user enters something that is not in the array of valid responses, the message is displayed again and the method waits for more input. It will display the message a maximum of three times before it gives up and returnsnull.- Parameters:
message- The message/question to display.validResponses- An array of responses that the user is allowed to enter. Displayed after the message.- Returns:
- The line of text entered by the user, or
nullif the user never entered a valid string.
-
error
public void error(java.lang.String label, java.lang.String message)Description copied from interface:ConsoleLoggerLog an error with a specific error label- Specified by:
errorin interfaceConsoleLogger- Parameters:
label- The labelmessage- The message
-
restoreOriginalSystemOutAndErr
public void restoreOriginalSystemOutAndErr()
-
cleanlyExit
public void cleanlyExit(int status)
-
flush
public void flush()
Makes sure that the console has been reset to the default state and that the out stream has been flushed.
-
getDefaultInputMask
public java.lang.Character getDefaultInputMask()
-
setDefaultInputMask
public void setDefaultInputMask(java.lang.Character defaultInputMask)
-
-