LibMuse 6.0.3
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:


To install a custom log listener for your application:


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


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

Member Function Documentation

§ getTimestamp()

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

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.

The current timestamp.

§ instance()

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

Returns the shared log manager instance.

The shared log manager instance.

§ makeDefaultLogListener()

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

Constructs and returns a default log listener.

an instance of the default log listener.

§ setLogListener()

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

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.

listenerthe LogListener to use.

§ setMinimumSeverity()

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

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.

severitythe minimum log severity to log.

§ timeSince()

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

Return the time elapsed in seconds since the passed timestamp.

timestampThe prior timestamp.

§ writeLog()

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

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.

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: