The class can be used in a builder pattern, instantiated by one of the static methods based on severity, and then calling println() for finishing. The instances are reusable.
The class defines a severity, which specifies the error level of the printed message. Each error message with a given
severity will begin with an appropriate word for it. E.g. "Error"
.
The logger will print the messages to the specified output, or to a default stream when unspecified. The default stream is based on the current task (if any), else it will be printed to the current standard output of the process. In case it is necessary, the message will be encoded using UTF-8.
A path can be specified for the log messages, which will be prepended to the printed line.
Line and line positions can be specified for the log messages, which will be written out after the path. Line positions are only printed when a path was set.
The printed output has the following format:
The phrases between brackets are hierarchically optional.
[path][:line][:posstart][-posend]: [severity]: [message]Line number information is only present if a path was specified. Line position is only present, if line number is present. Intermediate
": "
is omitted if no phrase comes after it.
This class also contains some utility functions for formatting other logging information.
Note: Functionality that automatically prints on the task standard
output without a specified TaskContext as the output relies on an internal inheritable thread local variable. If you use your own threading implementation and don't inherit thread locals,
make sure to explicitly call out(
public enum | Common ExceptionFormat implementation enumeration. |
public interface | Interface for defining how a given exception should be displayed to the stream. |
public static final int | SEVERITY_ERROR = 3 Severity for errors. |
public static final int | SEVERITY_INFO = 1 Severity about generic information. |
public static final int | SEVERITY_PLAIN = 0 Severity representing no severity. |
public static final int | SEVERITY_SUCCESS = 4 Severity for representing success. |
public static final int | SEVERITY_WARNING = 2 Severity for warnings. |
public static SakerLog | error() Creates a logger with severity of SEVERITY_ERROR. |
public static SakerLog | info() Creates a logger with severity of SEVERITY_INFO. |
public SakerLog | line( Sets the display line for this logger instance. |
public static SakerLog | log() Creates a logger with severity of SEVERITY_PLAIN. |
public SakerLog | out( Sets the display output for this logger instance. |
public SakerLog | out( Sets the display output task for this logger instance. |
public SakerLog | Sets the path to display for this logger. |
public SakerLog | position( Sets the range in the line for this logger instance. |
public static void | Prints a formatted exception view to the standard error with the default exception
format. |
public static void | printFormatException( Prints a formatted exception view to the specified stream with the default exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified stream with the specified exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified stream with the specified exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified output with the default exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified output with the specified exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified output with the specified exception format. |
public static void | Prints a formatted exception view to the specified string builder with the default exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified string builder with the specified exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified string builder with the specified exception format. |
public static void | printFormatException( Prints a formatted exception view to the standard error with the default exception
format. |
public static void | printFormatException( Prints a formatted exception view to the specified stream with the default exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified output with the default exception format. |
public static void | printFormatException( Prints a formatted exception view to the specified string builder with the default exception format. |
public static void | printFormatException( Prints a formatted exception view to the standard error with the specified exception
format. |
public static void | printFormatException( Prints a formatted exception view to the standard error with the specified exception
format. |
public static void | printFormatExceptions( Prints multiple formatted exception views to the specified stream with the specified exception format. |
public static void | printFormatExceptions( Prints multiple formatted exception views to the specified output with the specified exception format. |
public static void | printFormatExceptions( Prints multiple formatted exception views to the specified string builder with the specified exception format. |
public void | println() Prints a line with empty message. |
public void | Prints a line with the argument object as a message. |
public static SakerLog | severity( Creates a new logger with the specified severity. |
public static SakerLog | success() Creates a logger with severity of SEVERITY_SUCCESS. |
public SakerLog | taskScriptPosition( Modifies the logger to print its contents using the given task context and have the path and positional
information of it. |
public SakerLog | verbose() Sets the display output for this logger instance to be verbose. |
public static SakerLog | warning() Creates a logger with severity of SEVERITY_WARNING. |
Will create a message without any severity phrase.
The line is 0 (zero) indexed.
Line information is displayed only if there was a path set.
this
this
null
.
The logger will use TaskContext.println(
Note: this logger instance won't be reusable outside of this task execution, unless the output is reset.
this
null
.
The logger will attempt to relativize the path based on the current task information. If this method is called in
a context of a build system task, then SakerPathFiles.toRelativeString(
null
to disable it.this
Parameters are 0 (zero) indexed.
Only affects the output if line(
If the line end parameter extends beyond the actual end of the line, the range is considered to be multi-line.
If the line start is non-negative, and the line end less than line start, the only the offset in the line is set.
this
null
.null
.null
to don't relativize.null
.null
.null
.null
.null
.null
to don't relativize.null
.null
.null
.null
.null
.null
to don't relativize.null
.null
.null
.null
.null
to don't relativize.null
.null
to don't relativize.null
.null
to don't relativize.null
.null
to don't relativize.null
.null
to don't relativize.null
.null
.null
.null
.null
to don't relativize.null
.null
.null
to don't relativize.null
.null
.null
to don't relativize.null
.null
.Any path, line, and severity information will be printed to the output, but no message.
It is strongly recommended to call println(
The argument will be converted to String via StringBuilder.append(
A "null"
message will be printed if the argument is null
.
SEVERITY_*
constants defined by this class.SEVERITY_*
constants of this class.This method will caues the logger to have the path and positional information that can be determined based on the currently executing task. This usually results in the appropriate script path and script position to be displayed in the log message.
Calling this method will also cause the task context to be used for printing the message.
Calling the display output modification methods of this logger will cause the script positional information to not be printed.
Calling path and positional information modifying methods without also replacing the display output will have no effect.
this
null
.
Verbose output will not display the message using TaskContext.println(
this