LibMuse 6.0.2
com.choosemuse.libmuse.LogManager Class Referenceabstract

Public Member Functions

abstract LogListener makeDefaultLogListener ()
 
abstract void setLogListener (LogListener listener)
 
abstract void setMinimumSeverity (Severity severity)
 
abstract void writeLog (Severity severity, boolean raw, String tag, String message)
 
abstract long getTimestamp ()
 
abstract double timeSince (long timestamp)
 

Static Public Member Functions

static native LogManager instance ()
 

Detailed Description

Manages the listener for any logging events generated by LibMuse.

To disable logging:

setLogListener(null);

To install a custom log listener for your application:

setLogListener(your_log_listener);

To restore default logging to standard error (if you have previously changed the log listener):

setLogListener(makeDefaultLogListener());

An instance of the default listener is installed unless another listener is supplied. The default log listener prints all messages to standard error as they show up, without any buffering, using the following formatting rules:

  • Raw logs are printed directly without any formatting or newline.
  • Other messages are formatted to pretty-print with the tag, timestamp, severity, and log message on a single line (prepending a newline if the last message printed was raw.)

For example, suppose that these packets showed up in order: {info, false, "A", 4, "thing A"}, {info, true, "FOO", 1, "+"}, {err, true, "BAR", 3, "-"}, {warn, false, "B", 2, "thing B"} where the second parameter idicates if this is a raw log message. The log output would be formatted roughly as such:

A [I 4.000] thing A
+-
B [W 2.000] thing B

In order to provide this formatting without buffering or losing messages, the default log listener uses a mutex, effectively making the logging subsystem single-threaded and IO-bound.

See also
LogListener

Member Function Documentation

§ getTimestamp()

abstract long com.choosemuse.libmuse.LogManager.getTimestamp ( )
abstract

Return the current timestamp.

The returned value is in microseconds since some epoch – January 1 1970 on UNIX, but possibly other values on other systems.

Returns
The current timestamp.

§ instance()

static native LogManager com.choosemuse.libmuse.LogManager.instance ( )
static

Returns the shared log manager instance.

Returns
The shared log manager instance.

§ makeDefaultLogListener()

abstract LogListener com.choosemuse.libmuse.LogManager.makeDefaultLogListener ( )
abstract

Constructs and returns a default log listener.

Returns
an instance of the default log listener.

§ setLogListener()

abstract void com.choosemuse.libmuse.LogManager.setLogListener ( LogListener  listener)
abstract

Sets the log listener.

There is only one log listener active at a time; hence this is just a plain setter rather than a register / unregister pair.

Parameters
listenerthe LogListener to use.

§ setMinimumSeverity()

abstract void com.choosemuse.libmuse.LogManager.setMinimumSeverity ( Severity  severity)
abstract

Set the minimum log severity.

Messages at or above this severity will be passed to the configured log listener. Messages below this severity will be dropped.

Parameters
severitythe minimum log severity to log.

§ timeSince()

abstract double com.choosemuse.libmuse.LogManager.timeSince ( long  timestamp)
abstract

Return the time elapsed in seconds since the passed timestamp.

Parameters
timestampThe prior timestamp.

§ writeLog()

abstract void com.choosemuse.libmuse.LogManager.writeLog ( Severity  severity,
boolean  raw,
String  tag,
String  message 
)
abstract

Write a log line.

This method sends messages to the configured log listener. It is exposed here primarily so that LibMuse can access it from its own platform-specific code, but there's nothing stopping you from using it and doing all your logging through LibMuse. Except please don't, because we may change the API at any time, and why would you?

The log's timestamp is the number of seconds since this log manager was created.

Parameters
severityThe severity of this log message.
rawtrue if this is a raw log message (no formatting), false otherwise
tagThe tag for this message.
messageThe log message.

The documentation for this class was generated from the following file: