SimpleLogger ClassLocate this document in the navigation structure

Use

This new class is easier to use than the methods in Category and Location .

It contains less output methods, providing enough functionality for your logging/tracing tasks.

SimpleLogger Method

Parameters

Description

public static boolean isWritable

(int severity, LogController lc)

Determines if a message with provided severity passes Log Controller's severity check. If so, the message is written.

public static LogRecord log

(int severity, Category category, Location location, String message, String messageID)

Logs message with specified severity and emits it to the Location parameter.

public static LogRecord log

(int severity, Category category, Location location, String message, String messageID, Object[] args)

Logs message with specified severity and emits it to the Location parameter.

Replaces argument values directly in the log message

public static LogRecord trace

(int severity, Location location, String message)

Traces a message with specified severity.

public static LogRecord trace

(int severity, Location location, String message, String messageID)

Traces a message with specified severity.

public static LogRecord trace

(int severity, Location location, String message, St ring messageID, Object[] args)

Traces a message with specified severity. Replaces argument values directly in the trace message.

public static LogRecord traceThrowable

(int severity, Location location, String message, String messageID, Object[] args, Throwable exc)

Traces exception and its stack trace with the specified severity.

public static LogRecord traceThrowable

(int severity, Location location, String message, String messageID, Throwable exc)

Traces exception and its stack trace with the specified severity.

public static LogRecord traceThrowable

(int severity, Location location, String message, Throwable exc)

Traces exception and its stack trace with the specified severity.

Example

package com.sap.fooPackage;
import com.sap.tc.logging.*;
public class Node {
  private Object row[];
       //using the obsolete methods in "Category" and "Location"
  
private static finalLocation loc =
    Location.getLocation("com.sap.fooPackage.Node");
  private static final Category cat = 
    Category.getCategory(Category.SYS_DATABASE, "Node");
  public void announce(Object o) {
    String method = "announce(java.lang.Object)";
       // Perform a task, e.g. connecting to DB.
    try {
      // It won't be logged, since severity DEBUG is lower than WARNING.
      // using the SimpleLogger class  
      SimpleLogger.trace(Severity.DEBUG, loc, 
                                 method + " - " + "Connecting to ...");
      //minor error when writing something
      SimpleLogger.trace(Severity.WARNING, loc, 
                                 "Problems in row {0} to {1}",
                                                       row[0], row[1]);
      //error in the connection
      SimpleLogger.log(Severity.ERROR, cat, loc, "ASJ.dbn.000023", 
                                              "DB connection failure");
    } catch (Exception e) {
       SimpleLogger.log(Severity.ERROR, cat, loc, "ASJ.dbn.000024", 
                        "Error storing node {0} in database.", row[0]);
      }
  }  // method announced
}  // class NodeEnd of the code.

         
More Information

If you want to provide log messages via the methods in Category and Location , see Enable Output Messages .