Show TOC

Background documentationMessage Output with Severity Locate this document in the navigation structure

 

Use the following output methods with severity:

  • Location – fatalT, errorT, warningT, infoT, pathT, debugT.

  • Category – fatalT, errorT, warningT, infoT.

The names concerning the severity level of the messages, generated by these methods are self-explanatory. The overloaded pattern is the same for each severity output.

Recommendation Recommendation

These output methods are outdated but not deprecated. You can use them at will.

We recommend that you use the new class com.sap.tc.logging.SimpleLogger.

More information: SimpleLogger Class

End of the recommendation.

In the table below, the pattern is masked with 'xxxx':

The basic methods are:

Location

Category

xxxxT(String message)

xxxxT(Location loc, String message)

xxxxT(String subloc, String message)

xxxxT(Location loc, String subloc, String message)

xxxxT(String message, Object[] args)

xxxxT(Location loc, String message, Object[] args)

xxxxT(String subloc, String message, Object[] args)

xxxxT(Location loc, String subloc, String message, Object[] args)

There is a pattern in the method overloading that revolves the core argument – message. The addition of subloc and args offers flexibility for logging messages at the level of details that they need.

Understanding these arguments makes it easier for you to select the heavily overloaded methods:

Argument Name

Description

loc

A typical request that log messages are always written with to a source code area. This argument is the only difference in the API between location and category in the category output methods.

By specifying the loc argument, you indicate that the message must be written as a trace message associated with the loc object.

More information: Relations Between Category and Location.

subloc

The method name , from which the message is generated. This is optional, but including this argument in the trace/log, makes the analysis more clear.

In particular, you can specify different arguments for overloaded methods.

message

Contains the actual message to be printed.

args

An array of additional arguments that are informative.

In case of tracing, each placeholder in the message (for example, {0}, {1}) is replaced by its arguments. For example, {0}, {1},... is replaced by args[0].toString(), args[1].toString(),...

In case of logging, argument values are appended to the record entry.

If you use the Log Viewer to view logs/traces, it evaluates the placeholders.

Example

Working on a Location Object

Syntax Syntax

  1. package com.sap.fooPackage;
    
    import com.sap.tc.logging.*;
    
    public class Node {
       private static final Location loc =
          Location.getLocation("com.sap.fooPackage.Node");
       public void announce(Object o) {
          String method = "announce(java.lang.Object)";
          try {
          // do something...e.g. connecting to DB, perform certain actions
          // it will not be logged, severity DEBUG is lower than WARNING    
          loc.debugT(method, "Connecting to ….“);
          //minor error in writing something
          loc.warningT(method,
                              "Problems in row {0} to {1}“,
                               new Object[] {row1, rowN});
          //error in the connection
          loc.errorT(method, "DB connection failure“);
       }   
       catch (Exception e) {
       }
      }  // method announce
    }  // class Node
End of the code.

Potential output, assuming the simplest case with ConsoleLog and default TraceFormatter:

May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Warning: Problems in row 15 to 18 May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Info: DB connection failure

Working on a Category Object

Syntax Syntax

  1. package com.sap.fooPackage;
    
    import com.sap.tc.logging.*;
    
    public class Node {
       private static final Location loc =
          Location.getLocation("com.sap.fooPackage.Node");
       private static final Category cat =
          Category.getCategory("/System/Database");
       public void store() {
          try { // Write object data to database ...
          }
          catch (FailedRegistrationException e) {
            cat.errorT(loc, "store()", "Error storing node {0} in database.",
                                                        new Object[] {this});
          }
       }  // method store
    }  // class Node
End of the code.

Note Note

The output is identical to the "Working on a Location Object" example, assuming the default setting (with ConsoleLog and default TraceFormatter).

End of the note.