public class Log
extends java.lang.Object
This class provides an independent logging capability available to both Java and non-Java SAFS clients. Non-Java clients will write to this log through STAF using the STAF QUEUE of a registered "SAFS/TESTLOG" client of this class. Java clients will simply write to the static methods of this Log class.
The class is intended to act as a development, debugging, and troubleshooting log allowing SAFS clients to write detailed information to this separate log that will not clutter the normal log output during production testing.
Typical usage of this class requires the following steps:
Example debug Log invocations:
Example (a) shows launching the debug Log with the default DEBUG log level.
Examples (b) and (c) are examples launching the debug Log with the INFO log level.
The static main method will launch the debug console and receive 'logmsg' messages on it's STAF QUEUE.
Some log levels, like INFO and INDEX, will always log to this class since they are ONLY used during development/maintenance and will never be written to SAFSLOGS. The org.safs.logging.LogUtilities class can also be enabled to forward messages to this class, if that is desirable.
The internal 'message' method will first try to send using STAF using the 'logmsg' method, if that fails, then it will simply do a System.out.println.
The formatted_message is expected to be in the following format:
The debug Log has some special reserved messages:
So, in order to change the level to WARN, do this:
OR
staf local queue queue name SAFS/TESTLOG message LEVELwarn
And to shutdown the debug Log, do this:
Modifier and Type | Field and Description |
---|---|
static int |
DEBUG
"0" DEBUG log level.
|
static boolean |
ENABLED
Enables/Disables the use of this class for performance reasons.
|
static int |
ERROR
"6" ERROR log level.
|
static int |
GENERIC
"3" GENERIC log level.
|
static int |
INDEX
"2" INDEX log level.
|
static int |
INFO
"1" INFO log level.
|
(package private) static int |
level |
protected static java.lang.String |
log_processname |
static int |
PASS
"4" PASS log level.
|
static java.lang.String |
SAFS_TESTLOG_CLIENT
"SAFSTESTLOGClient" -- registered STAF Process name for other JVM/processes.
|
static java.lang.String |
SAFS_TESTLOG_CLS
"CLS" -- Command to clear lines in the debug console to separate logging sessions.
|
static java.lang.String |
SAFS_TESTLOG_FILE
"-file:" -- Command-line prefix to enable output to file.
|
static java.lang.String |
SAFS_TESTLOG_HELP
"HELP" -- Command to show the Help info in the debug console.
|
static java.lang.String |
SAFS_TESTLOG_LEVEL
"LEVEL" -- root command for setting the log level.
|
static java.lang.String |
SAFS_TESTLOG_LIST
"LIST" -- Command to show the Help info in the debug console.
|
static java.lang.String |
SAFS_TESTLOG_PROCESS
"SAFS/TESTLOG" - registered STAF Process name for the primary debug console.
|
static java.lang.String |
SAFS_TESTLOG_RESUME
"RESUME" -- Command to RESUME debug logging.
|
static java.lang.String |
SAFS_TESTLOG_SHUTDOWN
"SHUTDOWN" -- Command to close the debug console and unregister with STAF.
|
static java.lang.String |
SAFS_TESTLOG_SUSPEND
"SUSPEND" -- Command to SUSPEND debug logging temporarily.
|
static java.lang.String |
SAFS_TESTLOG_VARIABLE
"SAFS/TESTLOG/MSG" -- SAFSVARS variable to monitor sent messages.
|
protected static java.lang.String[] |
strlevel |
static int |
WARN
"5" WARN log level.
|
Constructor and Description |
---|
Log() |
Modifier and Type | Method and Description |
---|---|
static void |
close()
Doesn't do anything unless we are running Embedded.
|
static void |
debug(java.lang.Object msg) |
static void |
debug(java.lang.Object msg,
java.lang.Throwable ex) |
static void |
error(java.lang.Object msg) |
static void |
error(java.lang.Object msg,
java.lang.Throwable ex) |
static void |
generic(java.lang.Object msg) |
static java.lang.String |
getHelp()
Returns the Help text seen in the SAFS/TESTLOG console.
|
static int |
getLogLevel() |
protected static int |
getStrLevel(java.lang.String slevel)
Parse a string log level into its equivalent int log level value.
|
static void |
index(java.lang.Object msg) |
static void |
info(java.lang.Object msg) |
static void |
info(java.lang.Object msg,
java.lang.Throwable ex) |
static boolean |
isEmbedded() |
static void |
main(java.lang.String[] args)
Run standalone to activate the debug console.
|
static void |
message(int logLevel,
java.lang.Object msg)
Purpose: logs using 'logmsg' if that fails, then does console. |
(package private) static void |
message(int logLevel,
java.lang.String levelMsg,
java.lang.Object msg)
Purpose: logs using 'logmsg' if that fails, then does console. |
static void |
pass(java.lang.Object msg) |
static boolean |
resume() |
static void |
runEmbedded(java.lang.String[] args)
Call to make the SAFS Debug Log--normally a separate Java Process--run embedded inside
the test process in a separate Thread.
|
static void |
setDoLogMsg(boolean _doLogMsg) |
static void |
setHelper(STAFHelper aHelper) |
static void |
setLogLevel(int loglevel) |
static void |
setLogProcessName(java.lang.String _processName)
Used to preset a Log processName prior to any STAFHelper initialization.
|
static boolean |
suspend() |
static void |
warn(java.lang.Object msg) |
public static boolean ENABLED
public static final java.lang.String SAFS_TESTLOG_PROCESS
public static final java.lang.String SAFS_TESTLOG_CLIENT
public static final java.lang.String SAFS_TESTLOG_VARIABLE
public static final java.lang.String SAFS_TESTLOG_SHUTDOWN
public static final java.lang.String SAFS_TESTLOG_SUSPEND
public static final java.lang.String SAFS_TESTLOG_RESUME
public static final java.lang.String SAFS_TESTLOG_CLS
public static final java.lang.String SAFS_TESTLOG_LEVEL
public static final java.lang.String SAFS_TESTLOG_LIST
public static final java.lang.String SAFS_TESTLOG_HELP
public static final java.lang.String SAFS_TESTLOG_FILE
public static final int DEBUG
public static final int INFO
public static final int INDEX
public static final int GENERIC
public static final int PASS
public static final int WARN
public static final int ERROR
static int level
protected static final java.lang.String[] strlevel
protected static java.lang.String log_processname
public static void runEmbedded(java.lang.String[] args)
args
- -- Same as for main(String[] args)--which will be invoked with a new Thread.public static boolean isEmbedded()
protected static int getStrLevel(java.lang.String slevel)
public static void setLogLevel(int loglevel)
public static int getLogLevel()
public static void setDoLogMsg(boolean _doLogMsg)
static void message(int logLevel, java.lang.String levelMsg, java.lang.Object msg)
logLevel
- intlevelMsg
- Stringmsg
- Object, message to send (.toString() is used)public static void message(int logLevel, java.lang.Object msg)
logLevel
- int, the log levelmsg
- Object, message to send (.toString() is used)public static boolean suspend()
public static boolean resume()
public static void debug(java.lang.Object msg)
public static void info(java.lang.Object msg)
public static void index(java.lang.Object msg)
public static void generic(java.lang.Object msg)
public static void pass(java.lang.Object msg)
public static void warn(java.lang.Object msg)
public static void error(java.lang.Object msg)
public static void error(java.lang.Object msg, java.lang.Throwable ex)
public static void info(java.lang.Object msg, java.lang.Throwable ex)
public static void debug(java.lang.Object msg, java.lang.Throwable ex)
public static void close()
public static java.lang.String getHelp()
public static void main(java.lang.String[] args)
Accepts a command line argument that allows you to specify the initial log level. The format is strictly the numeric log level ("0" thru "6") or the equivalent text ("debug" thru "error").
Examples:
Also accepts a command line argument to write log messages to file.
Examples:
And, of course, both command-line arguments can be used in the same call.
public static void setHelper(STAFHelper aHelper)
public static void setLogProcessName(java.lang.String _processName)
_processName
- Copyright © SAS Institute. All Rights Reserved.