LogUtil

Framework Components [com.onepg.util]

← Back to Class List

Class Information

Package: com.onepg.util

Class Name: LogUtil

Description

Log utility class.

Method List

newLogWriter

public LogWriter newLogWriter(Class<?> cls)
Creates a log writer instance.

Parameters

Name Type Description
cls Class<?> log target class

Return Value

LogWriter - log writer instance

newLogWriter

public LogWriter newLogWriter(Class<?> cls, String traceCode)
Creates a log writer instance.

Parameters

Name Type Description
cls Class<?> log target class
traceCode String trace code

Return Value

LogWriter - log writer instance

stdout

public void stdout(String... msgs)
Outputs to standard output.

Parameters

Name Type Description
msgs String... messages

stdout

public void stdout(Throwable e, String... msgs)
Outputs to standard output.

Parameters

Name Type Description
e Throwable error object
msgs String... messages

javaInfoStdout

public void javaInfoStdout()
Outputs Java information to standard output.

isDevelopMode

public boolean isDevelopMode()
Checks development mode.

Return Value

boolean - true if in development mode

getStackTrace

public String getStackTrace(String lineSep, Throwable e)
Gets the stack trace of an error object.
  • Stops getting stack trace if it is BreakException.

Parameters

Name Type Description
lineSep String line separator
e Throwable error object

Return Value

String - stack trace

joinKeyVal

public String joinKeyVal(Object... keyVal)
Joins key-value strings.
  • Joins in the format "key=value, key=value, key=value,..." to create a log string.
  • If the value is an array, list, or map, calls the respective join method to join them.

Parameters

Name Type Description
keyVal Object... key-value pairs (key, value, key, value, key, value,...)

Return Value

String - joined string in the format "key=value, key=value, key=value"

joinValues

public String joinValues(String... values)
Joins values.
  • Joins in the format "value, value,... " to create a log string.

Parameters

Name Type Description
values String... values to join

Return Value

String - string in the format "value, value, value, value"

join

public String join(String[] values)
Joins array values.
  • Joins in the format " [value, value,...] " to create a log string.

Parameters

Name Type Description
values String[] values to join

Return Value

String - string in the format "[value, value, value, value]"

join

public String join(List<?> values)
Joins list values.
  • Joins values in the list in the format " [value, value,...] " to create a log string.

Parameters

Name Type Description
values List<?> list to join

Return Value

String - string in the format "[value, value, value, value]"

join

public String join(Map<String, T> map)
Joins map key-value pairs.
  • Joins keys and values in the map in the format " {key=value, key=value, key=value,...} " to create a log string.

Parameters

Name Type Description
map Map<String, T> map to join

Return Value

String - string in the format "{key=value, key=value, key=value}"

replaceNullValue

public String replaceNullValue(String value)
Replaces null.
If the value is null, returns the replacement character for logging.

Parameters

Name Type Description
value String replacement character if null

Return Value

String - the value as is if not null, replacement character if null

formatDaysTime

public String formatDaysTime(long msec)
Formats date-time.
  • Converts milliseconds to readable format (days, hours, minutes, seconds, milliseconds).
  • Example: "11T03:15:30.123", "0T01:00:00.000"

Parameters

Name Type Description
msec long milliseconds

Return Value

String - formatted uptime

getClassNameAndLineNo

public String getClassNameAndLineNo(Class<?> callerClass)
Gets caller information.
  • Gets the class package + class name + line number of the caller from the stack trace.

Parameters

Name Type Description
callerClass Class<?> caller class

Return Value

String - class package + class name + line number