Implements: IReconfigurable, IReferenceable, ITracer
Description
The LogTracer class allows you to create a tracer that dumps recorded traces to a logger.
Configuration parameters
options:
- log_level: log level to record traces (default: debug)
References
- *:logger:*:*:1.0 - ILogger components to dump the captured counters
- *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify counters source
Instance methods
begin_trace
Begings recording an operation trace.
public TraceTiming beginTrace([IContext](../../../components/context/icontext context, String component, String operation)
- context: IContext - (optional) a context to trace execution through a call chain.
- component: String - name of the called component
- operation: String - name of the executed operation.
- return: TraceTiming - a trace timing object.
configure
Configures component by passing configuration parameters.
void configure(ConfigParams config) throws ConfigException
- config: ConfigParams - configuration parameters to be set.
failure
Records an operation failure with its name, duration and error
void failure(IContext context, String component, String operation, Exception error, long duration)
- context: IContext - (optional) a context to trace execution through a call chain.
- component: String - name of the called component
- operation: String - name of the executed operation.
- error: Exception - an error object associated with this trace.
- duration: long - execution duration in milliseconds.
set_references
Sets references to dependent components.
void setReferences(IReferences references)
- references: IReferences - references to locate the component dependencies.
trace
Records an operation trace with its name and duration.
void trace(IContext context, String component, String operation, Long duration)
- context: IContext - (optional) a context to trace execution through a call chain.
- component: String - name of the called component
- operation: String - name of the executed operation.
- duration: Long - execution duration in milliseconds.
Examples
{@code
LogTracer tracer = new LogTracer();
tracer.setReferences(References.fromTuples(
new Descriptor("pip-services", "logger", "console", "default", "1.0"), new ConsoleLogger()
));
TraceTiming timing = trcer.beginTrace("123", "mycomponent", "mymethod");
try {
...
timing.endTrace();
} catch(err) {
timing.endFailure(err);
}
}