Loading TOC...
Java Application Developer's Guide (PDF)

Java Application Developer's Guide — Chapter 11

Logging

RequestLogger objects are supplied to individual manager objects, most commonly document and query managers. You can choose to log content sent to the server as well as any requests. It is located in com.marklogic.client.util.

This chapter includes the following sections:

Starting Logging

First, you must obtain a RequestLogger object via DatabaseClient's newLogger() method, which takes an argument of an output stream to send the log messages to. This output stream can be shared with other loggers outside of the MarkLogic Server Java API. You are responsible for flushing the output stream.

out = new ByteArrayOutputStream();
RequestLogger logger = client.newLogger(out);

To start logging, call the startLogging() method on a manager object with an argument of a RequestLogger object. For example:

MyDocumentManager.startLogging(logger)

There is only one logger for any given object. However, you can share a RequestLogger object among multiple manager objects, just by specifying the same RequestLogger object in multiple startLogging() method calls.

Suspending and Resuming Logging

By using RequestLogger's setEnabled() method, you can pause and resume logging on any logger object. For example, to suspend logging:

logger.setEnabled(false)

To reenable logging:

logger.setEnabled(true)

To check if logging is enabled or not:

logger.isEnabled(); //returns a boolean

When you change a logger's enable status, it applies to all manager objects for which that RequestLogger object was used as an argument to StartLogging().

Stopping Logging

To stop logging on a manager, call the stopLogging() method. If called on a manager not currently logging, nothing happens, not even an error or exception. The RequestLogger object associated with the manager is not destroyed by this method and you can reuse and restart it.

MyDocumentManager.stopLogging()

Log Entry Format

Two types of things can be logged once logging is turned on and enabled. Requests to the server are always logged. These include search requests, configuration requests, and all database requests. By default, only requests are logged.

You can use RequestLogger's setContentMax() method to control how much content is logged. By giving it the constant ALL_CONTENT value, all content is logged. To revert to no content being logged, use the constant NO_CONTENT. If you use a numeric value, such as 1000, the first that many content bytes are logged. Note that if the request is for a deletion, no content is logged.

FileHandle is an exception to the ability to log content. Only the name of the file is logged.

You can also retrieve a request logger's underlying print stream by calling getPrintStream() on the RequestLogger object. Once you access the log's print stream, writing to it adds your own messages to the log.

Logging To The Server's Error Log

You can also use ServerConfigurationManager.setServerRequestLogging()to turn logging requests to the server's error log on or off, based on the boolean argument you provide. This log's location is platform dependent. For details about log files in MarkLogic Server, see Log Files in the Administrator's Guide.

« Previous chapter
Next chapter »
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy