Package: grails.build.logging

## [Java] Class GrailsConsole

- grails.build.logging.GrailsConsole

- All Implemented Interfaces and Traits:
    ConsoleLogger

      public class GrailsConsole
      extends java.lang.Object
      implements ConsoleLogger

  Utility class for delivering console output in a nicely formatted way.

  Authors:
    Graeme Rocher
  Since:
    2.0

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static java.lang.String` | `CATEGORY_SEPARATOR` |
    `static java.lang.String` | `ENABLE_INTERACTIVE` |
    `static java.lang.String` | `ENABLE_TERMINAL` |
    `static java.lang.String` | `ERROR` |
    `static java.lang.String` | `HISTORYFILE` |
    `static java.lang.String` | `LINE_SEPARATOR` |
    `static java.lang.String` | `PROMPT` |
    `static java.lang.Character` | `SECURE_MASK_CHAR` |
    `static java.lang.String` | `SPACE` |
    `static java.lang.String` | `STACKTRACE_FILTERED_MESSAGE` |
    `static java.lang.String` | `STACKTRACE_MESSAGE` |
    `static java.lang.String` | `WARNING` |
    `private boolean` | `ansiEnabled` | Whether ANSI should be enabled for output
    `private boolean` | `appendCalled` | Logs a message below the current status message
    `java.util.Stack<java.lang.String>` | `category` | The category of the current output
    `private int` | `cursorMove` |
    `private java.lang.Character` | `defaultInputMask` |
    `java.io.PrintStream` | `err` |
    `jline.console.history.History` | `history` |
    `java.lang.String` | `indicator` | The progress indicator to use
    `private static GrailsConsole` | `instance` |
    `java.lang.String` | `lastMessage` | The last message that was printed
    `org.fusesource.jansi.Ansi` | `lastStatus` |
    `private java.lang.StringBuilder` | `maxIndicatorString` |
    `private java.io.PrintStream` | `originalSystemErr` |
    `private java.io.PrintStream` | `originalSystemOut` |
    `java.io.PrintStream` | `out` |
    `private boolean` | `progressIndicatorActive` |
    `jline.console.ConsoleReader` | `reader` | The reader to read info from the console
    `private java.lang.Thread` | `shutdownHookThread` |
    `private boolean` | `stacktrace` | Whether to show stack traces
    `jline.Terminal` | `terminal` |
    `private boolean` | `userInputActive` | Whether user input is currently active
    `private boolean` | `verbose` | Whether to enable verbose mode

  - ### Constructor Summary

    Constructors
    Constructor and description
    `protected GrailsConsole ()`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addShutdownHook()`
    `` | `public void` | `addStatus(java.lang.String msg)` Keeps doesn't replace the status message
    `` | `private org.fusesource.jansi.Ansi` | `ansiPrompt(java.lang.String prompt)`
    `` | `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.
    `` | `public void` | `append(java.lang.String msg)`
    `` | `private void` | `assertAllowInput()`
    `` | `private void` | `assertAllowInput(java.lang.String prompt)`
    `` | `public void` | `beforeShutdown()`
    `` | `protected void` | `bindSystemOutAndErr(java.io.PrintStream systemOut, java.io.PrintStream systemErr)`
    `` | `public void` | `cleanlyExit(int status)`
    `` | `protected jline.console.ConsoleReader` | `createConsoleReader(java.io.InputStream systemIn)`
    `` | `public static GrailsConsole` | `createInstance()`
    `` | `private java.lang.String` | `createQuestion(java.lang.String message, java.lang.String[] validResponses)`
    `` | `protected jline.Terminal` | `createTerminal()` Creates the instance of Terminal used directly in GrailsConsole.
    `` | `private java.lang.String` | `doUserInput(java.lang.String msg, boolean secure)`
    `` | `public void` | `echoStatus()` Replays the last status message
    `` | `private org.fusesource.jansi.Ansi` | `erasePreviousLine(java.lang.String categoryName)`
    `` | `private void` | `erasePrompt(java.io.PrintStream printStream)`
    `` | `public void` | `error(java.lang.String msg)` Prints an error message
    `` | `public void` | `error(java.lang.String msg, java.lang.Throwable error)` Use to log an error
    `` | `public void` | `error(java.lang.Throwable error)` Use to log an error
    `` | `public void` | `error(java.lang.String label, java.lang.String message)`
    `` | `public void` | `flush()` Makes sure that the console has been reset to the default state and that the out stream has been flushed.
    `` | `public java.util.Stack<java.lang.String>` | `getCategory()`
    `` | `public java.lang.Character` | `getDefaultInputMask()`
    `` | `public java.io.PrintStream` | `getErr()`
    `` | `public java.io.InputStream` | `getInput()` Returns: The input stream being read from
    `` | `public static GrailsConsole` | `getInstance()`
    `` | `public java.lang.String` | `getLastMessage()` Returns: The last message logged
    `` | `public java.io.PrintStream` | `getOut()`
    `` | `public jline.console.ConsoleReader` | `getReader()`
    `` | `public jline.Terminal` | `getTerminal()`
    `` | `public void` | `indicateProgress()` Indicates progress with the default progress indicator
    `` | `public void` | `indicateProgress(int number, int total)` Indicate progress for a number and total
    `` | `public void` | `indicateProgress(int number)` Indicates progress by number
    `` | `public void` | `indicateProgressPercentage(long number, long total)` Indicates progress as a percentage for the given number and total
    `` | `public void` | `info(java.lang.String msg)` Synonym for #log
    `` | `protected void` | `initialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr)`
    `` | `private boolean` | `isActivateTerminal()`
    `` | `public boolean` | `isAnsiEnabled()`
    `` | `public boolean` | `isInteractiveEnabled()`
    `` | `public boolean` | `isStacktrace()` Returns: Whether to show stack traces
    `` | `public boolean` | `isVerbose()` Returns: Whether verbose output is being used
    `` | `public boolean` | `isWindows()`
    `` | `public void` | `log(java.lang.String msg)` Logs a message below the current status message
    `` | `private void` | `logSimpleError(java.lang.String msg)`
    `` | `private org.fusesource.jansi.Ansi` | `moveDownToSkipPrompt()`
    `` | `private org.fusesource.jansi.Ansi` | `outputCategory(org.fusesource.jansi.Ansi ansi, java.lang.String categoryName)`
    `` | `private org.fusesource.jansi.Ansi` | `outputErrorLabel(org.fusesource.jansi.Ansi ansi, java.lang.String label)`
    `` | `private void` | `outputMessage(java.lang.String msg, int replaceCount)`
    `` | `protected void` | `persistHistory()`
    `` | `private void` | `postPrintMessage()`
    `` | `protected jline.console.history.History` | `prepareHistory()` Prepares a history file to be used by the ConsoleReader.
    `` | `private void` | `printStackTrace(java.lang.String message, java.lang.Throwable error)`
    `` | `private java.lang.String` | `readLine(java.lang.String prompt, boolean secure)`
    `` | `private boolean` | `readPropOrTrue(java.lang.String prop)`
    `` | `protected void` | `redirectSystemOutAndErr(boolean force)`
    `` | `public void` | `reinitialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr)` Use in testing when System.out, System.err or System.in change
    `` | `public static void` | `removeInstance()`
    `` | `public void` | `removeShutdownHook()`
    `` | `public void` | `resetCompleters()`
    `` | `public void` | `restoreOriginalSystemOutAndErr()`
    `` | `protected void` | `restoreTerminal()`
    `` | `public void` | `run()`
    `` | `public java.lang.String` | `secureUserInput(java.lang.String msg)` Like userInput(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.).
    `` | `public void` | `setAnsiEnabled(boolean ansiEnabled)`
    `` | `public void` | `setDefaultInputMask(java.lang.Character defaultInputMask)`
    `` | `public void` | `setErr(java.io.PrintStream err)`
    `` | `public static void` | `setInstance(GrailsConsole newConsole)`
    `` | `public void` | `setLastMessage(java.lang.String lastMessage)`
    `` | `public void` | `setOut(java.io.PrintStream out)`
    `` | `public void` | `setStacktrace(boolean stacktrace)` Parameters: `stacktrace` - Sets whether to show stack traces on errors
    `` | `public void` | `setVerbose(boolean verbose)` Parameters: `verbose` - Sets whether verbose output should be used
    `` | `private java.lang.String` | `showPrompt(java.lang.String prompt)` Shows the prompt to request user input
    `` | `public java.lang.String` | `showPrompt()` Shows the prompt to request user input
    `` | `public java.lang.String` | `toString()`
    `` | `private java.io.PrintStream` | `unwrapPrintStream(java.io.PrintStream printStream)`
    `` | `public void` | `updateStatus(java.lang.String msg)` Updates the current state message
    `` | `public java.lang.String` | `userInput(java.lang.String msg)` Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.
    `` | `public java.lang.String` | `userInput(java.lang.String message, java.util.List<java.lang.String> validResponses)`
    `` | `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.
    `` | `public void` | `verbose(java.lang.String msg)`
    `` | `private void` | `verifySystemOut()`
    `` | `public void` | `warn(java.lang.String msg)` Prints a warn message
    `` | `public void` | `warning(java.lang.String msg)` Prints an error message
    `` | `private java.io.PrintStream` | `wrapInPrintStream(java.io.PrintStream printStream)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Field Detail

    - #### public static final java.lang.String CATEGORY_SEPARATOR

    - #### public static final java.lang.String ENABLE_INTERACTIVE

    - #### public static final java.lang.String ENABLE_TERMINAL

    - #### public static final java.lang.String ERROR

    - #### public static final java.lang.String HISTORYFILE

    - #### public static final java.lang.String LINE_SEPARATOR

    - #### public static final java.lang.String PROMPT

    - #### public static final java.lang.Character SECURE_MASK_CHAR

    - #### public static final java.lang.String SPACE

    - #### public static final java.lang.String STACKTRACE_FILTERED_MESSAGE

    - #### public static final java.lang.String STACKTRACE_MESSAGE

    - #### public static final java.lang.String WARNING

    - #### private boolean ansiEnabled

      Whether ANSI should be enabled for output

    - #### private boolean appendCalled

      Logs a message below the current status message

      Parameters:
        `msg` - The message to log

    - #### @java.lang.SuppressWarnings("serial") java.util.Stack<java.lang.String> category

      The category of the current output

    - #### private int cursorMove

    - #### private java.lang.Character defaultInputMask

    - #### java.io.PrintStream err

    - #### jline.console.history.History history

    - #### java.lang.String indicator

      The progress indicator to use

    - #### private static GrailsConsole instance

    - #### java.lang.String lastMessage

      The last message that was printed

    - #### org.fusesource.jansi.Ansi lastStatus

    - #### private java.lang.StringBuilder maxIndicatorString

    - #### private java.io.PrintStream originalSystemErr

    - #### private java.io.PrintStream originalSystemOut

    - #### java.io.PrintStream out

    - #### private boolean progressIndicatorActive

    - #### jline.console.ConsoleReader reader

      The reader to read info from the console

    - #### private java.lang.Thread shutdownHookThread

    - #### private boolean stacktrace

      Whether to show stack traces

    - #### jline.Terminal terminal

    - #### private boolean userInputActive

      Whether user input is currently active

    - #### private boolean verbose

      Whether to enable verbose mode

  - ### Constructor Detail

    - #### protected GrailsConsole()

  - ### Method Detail

    - #### public void addShutdownHook()

    - #### @java.lang.Override public void addStatus(java.lang.String msg)

      Keeps doesn't replace the status message

      Parameters:
        `msg` - The message

    - #### private org.fusesource.jansi.Ansi ansiPrompt(java.lang.String prompt)

    - #### 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).

    - #### public void append(java.lang.String msg)

    - #### private void assertAllowInput()

    - #### private void assertAllowInput(java.lang.String prompt)

    - #### public void beforeShutdown()

    - #### protected void bindSystemOutAndErr(java.io.PrintStream systemOut, java.io.PrintStream systemErr)

    - #### public void cleanlyExit(int status)

    - #### protected jline.console.ConsoleReader createConsoleReader(java.io.InputStream systemIn)

    - #### public static GrailsConsole createInstance()

    - #### private java.lang.String createQuestion(java.lang.String message, java.lang.String[] validResponses)

    - #### 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.

    - #### private java.lang.String doUserInput(java.lang.String msg, boolean secure)

    - #### public void echoStatus()

      Replays the last status message

    - #### private org.fusesource.jansi.Ansi erasePreviousLine(java.lang.String categoryName)

    - #### private void erasePrompt(java.io.PrintStream printStream)

    - #### @java.lang.Override public void error(java.lang.String msg)

      Prints an error message

      Parameters:
        `msg` - The error message

    - #### @java.lang.Override public void error(java.lang.String msg, java.lang.Throwable error)

      Use to log an error

      Parameters:
        `msg` - The message
        `error` - The error

    - #### @java.lang.Override public void error(java.lang.Throwable error)

      Use to log an error

      Parameters:
        `error` - The error

    - #### @java.lang.Override public void error(java.lang.String label, java.lang.String message)

    - #### public void flush()

      Makes sure that the console has been reset to the default state and that the out stream has been flushed.

    - #### public java.util.Stack<java.lang.String> getCategory()

    - #### public java.lang.Character getDefaultInputMask()

    - #### public java.io.PrintStream getErr()

    - #### public java.io.InputStream getInput()

      Returns:
        The input stream being read from

    - #### public static GrailsConsole getInstance()

    - #### public java.lang.String getLastMessage()

      Returns:
        The last message logged

    - #### public java.io.PrintStream getOut()

    - #### public jline.console.ConsoleReader getReader()

    - #### public jline.Terminal getTerminal()

    - #### @java.lang.Override public void indicateProgress()

      Indicates progress with the default progress indicator

    - #### @java.lang.Override public void indicateProgress(int number, int total)

      Indicate progress for a number and total

      Parameters:
        `number` - The current number
        `total` - The total number

    - #### @java.lang.Override public void indicateProgress(int number)

      Indicates progress by number

      Parameters:
        `number` - The number

    - #### @java.lang.Override public void indicateProgressPercentage(long number, long total)

      Indicates progress as a percentage for the given number and total

      Parameters:
        `number` - The number
        `total` - The total

    - #### @java.lang.Override public void info(java.lang.String msg)

      Synonym for #log

      Parameters:
        `msg` - The message to log

    - #### protected void initialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr)

    - #### private boolean isActivateTerminal()

    - #### public boolean isAnsiEnabled()

    - #### public boolean isInteractiveEnabled()

    - #### public boolean isStacktrace()

      Returns:
        Whether to show stack traces

    - #### public boolean isVerbose()

      Returns:
        Whether verbose output is being used

    - #### public boolean isWindows()

    - #### @java.lang.Override public void log(java.lang.String msg)

      Logs a message below the current status message

      Parameters:
        `msg` - The message to log

    - #### private void logSimpleError(java.lang.String msg)

    - #### private org.fusesource.jansi.Ansi moveDownToSkipPrompt()

    - #### private org.fusesource.jansi.Ansi outputCategory(org.fusesource.jansi.Ansi ansi, java.lang.String categoryName)

    - #### private org.fusesource.jansi.Ansi outputErrorLabel(org.fusesource.jansi.Ansi ansi, java.lang.String label)

    - #### private void outputMessage(java.lang.String msg, int replaceCount)

    - #### protected void persistHistory()

    - #### private void postPrintMessage()

    - #### protected jline.console.history.History prepareHistory()

      Prepares a history file to be used by the ConsoleReader. This file will live in the home directory of the user.

    - #### private void printStackTrace(java.lang.String message, java.lang.Throwable error)

    - #### private java.lang.String readLine(java.lang.String prompt, boolean secure)

    - #### private boolean readPropOrTrue(java.lang.String prop)

    - #### protected void redirectSystemOutAndErr(boolean force)

    - #### public void reinitialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr)

      Use in testing when System.out, System.err or System.in change

      throws:
        IOException

    - #### public static void removeInstance()

    - #### public void removeShutdownHook()

    - #### public void resetCompleters()

    - #### public void restoreOriginalSystemOutAndErr()

    - #### protected void restoreTerminal()

    - #### @java.lang.Override public void run()

    - #### public java.lang.String secureUserInput(java.lang.String msg)

      Like userInput(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.

    - #### public void setAnsiEnabled(boolean ansiEnabled)

    - #### public void setDefaultInputMask(java.lang.Character defaultInputMask)

    - #### public void setErr(java.io.PrintStream err)

    - #### public static void setInstance(GrailsConsole newConsole)

    - #### public void setLastMessage(java.lang.String lastMessage)

    - #### public void setOut(java.io.PrintStream out)

    - #### public void setStacktrace(boolean stacktrace)

      Parameters:
        `stacktrace` - Sets whether to show stack traces on errors

    - #### public void setVerbose(boolean verbose)

      Parameters:
        `verbose` - Sets whether verbose output should be used

    - #### private java.lang.String showPrompt(java.lang.String prompt)

      Shows the prompt to request user input

      Parameters:
        `prompt` - The prompt to use
      Returns:
        The user input prompt

    - #### public java.lang.String showPrompt()

      Shows the prompt to request user input

      Returns:
        The user input prompt

    - #### @java.lang.Override public java.lang.String toString()

    - #### private java.io.PrintStream unwrapPrintStream(java.io.PrintStream printStream)

    - #### @java.lang.Override public void updateStatus(java.lang.String msg)

      Updates the current state message

      Parameters:
        `msg` - The message

    - #### 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.

    - #### public java.lang.String userInput(java.lang.String message, java.util.List<java.lang.String> validResponses)

    - #### 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 returns `null`.

      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 `null` if the user never entered a valid string.

    - #### @java.lang.Override public void verbose(java.lang.String msg)

    - #### private void verifySystemOut()

    - #### @java.lang.Override public void warn(java.lang.String msg)

      Prints a warn message

      Parameters:
        `msg` - The message

    - #### @java.lang.Override public void warning(java.lang.String msg)

      Prints an error message

      Parameters:
        `msg` - The error message

    - #### private java.io.PrintStream wrapInPrintStream(java.io.PrintStream printStream)