Using java.util.logging to figure the initial setup

With all its modularization, dependency injection and service location, it may be hard to figure the initial setup of a TrueZIP 7 application. Among other things, the initial setup determines which archive file suffixes will be detected by the application, e.g. .zip or .tar.gz. This post shows you how you can use java.util.logging to observe your application figuring its initial setup from the services available on the class path at runtime.

How The Initial Setup Is Figured

TrueZIP 7 uses some service locator singletons to figure its initial setup:

  1. Most prominently, the FsDriverLocator.SINGLETON determines which file system drivers are available for injection into the TrueZIP Kernel module for accessing file systems. These are used for all access to file systems, even the platform file system which is identified by the URI scheme file.
  2. Similarly, the IOPoolLocator.SINGLETON determines which I/O pool service is used for obtaining an I/O pool for allocating and releasing temporary buffers. When unit testing, an I/O pool is used which allocates and releases byte arrays. Otherwise, the TrueZIP Driver FILE module provides an implementation which uses temporary files.
  3. The FsManagerLocator.SINGLETON object determines the singleton file system manager to use. A custom implementation could be used for special purposes, such as monitoring the progress of archive file synchronization a.k.a. unmounting.
  4. Last, but not least, the TrueZIP Driver ZIP.RAES (TZP) uses the KeyManagerLocator.SINGLETON object to determine the singleton key manager service for resolving passwords for RAES encrypted ZIP files.

Monitoring The Service Locators

Because it can be hard to predict which services can be found on the run time class path, the aforementioned singletons use java.util.logging (JUL) to tell what they are doing. Note that apart from these singletons, logging is not used within any TrueZIP module - I will come back to this subject in a future post.

So here’s a sample configuration file you could use for monitoring these singletons:

############################################################
#  	        Logging Configuration File
#
# You can use this file by specifying a filename
# with the java.util.logging.config.file system property.
# For example java -Djava.util.logging.config.file=myfile
############################################################

############################################################
#  	Global properties
############################################################

# handlers specifies a comma separated list of log Handler
# classes.  These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# By default we only configure a ConsoleHandler, which will only
# show messages at the INFO and above levels.
# To also add the FileHandler, use the following line instead.
#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler

# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers.  For any given facility this global level
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level = INFO

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

# default file output is in user's home directory.
#java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.pattern = truezip%u-%g.log
java.util.logging.FileHandler.limit = 1000000
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

# At the CONFIG level, you will see the configuration of services
# found on the class path. Use this to debug your class path configuration.
de.schlichtherle.truezip.level = CONFIG

If you save this configuration file to logging.properties in the current directory, you would have to set the system property with -Djava.util.logging.config.file=logging.properties when running the JVM.

This configuration file will use two loggers, a file logger and a console logger. On the console, you will see only log records at Level.INFO and above. Because this is not used within TrueZIP, you should see nothing on the console. In the logging files, you will see log records at any level. The singletons log everything at Level.CONFIG. Running a TrueZIP application with this configuration might result in the following output:

05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsManagerLocator$Boot
KONFIG: Installing default file system manager: de.schlichtherle.truezip.fs.FsFailSafeManager[delegate=de.schlichtherle.truezip.fs.FsDefaultManager[size=0]]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Located file system driver service: de.schlichtherle.truezip.fs.file.FileDriverService
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Located file system driver service: de.schlichtherle.truezip.fs.archive.tar.TarDriverService
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Located file system driver service: de.schlichtherle.truezip.fs.archive.zip.raes.ZipRaesDriverService
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Located file system driver service: de.schlichtherle.truezip.fs.archive.zip.ZipDriverService
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme ear to file system driver: de.schlichtherle.truezip.fs.archive.zip.JarDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme exe to file system driver: de.schlichtherle.truezip.fs.archive.zip.ReadOnlySfxDriver[charset=windows-1252,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme file to file system driver: de.schlichtherle.truezip.fs.file.FileDriver[federated=false,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme jar to file system driver: de.schlichtherle.truezip.fs.archive.zip.JarDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme odb to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme odf to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme odg to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme odm to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme odp to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme ods to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme odt to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme otg to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme oth to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme otp to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme ots to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme ott to file system driver: de.schlichtherle.truezip.fs.archive.zip.OdfDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tar to file system driver: de.schlichtherle.truezip.fs.archive.tar.TarDriver[charset=US-ASCII,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tar.bz2 to file system driver: de.schlichtherle.truezip.fs.archive.tar.TarBZip2Driver[charset=US-ASCII,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tar.gz to file system driver: de.schlichtherle.truezip.fs.archive.tar.TarGZipDriver[charset=US-ASCII,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tb2 to file system driver: de.schlichtherle.truezip.fs.archive.tar.TarBZip2Driver[charset=US-ASCII,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tbz to file system driver: de.schlichtherle.truezip.fs.archive.tar.TarBZip2Driver[charset=US-ASCII,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tgz to file system driver: de.schlichtherle.truezip.fs.archive.tar.TarGZipDriver[charset=US-ASCII,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme tzp to file system driver: de.schlichtherle.truezip.fs.archive.zip.raes.SafeZipRaesDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme war to file system driver: de.schlichtherle.truezip.fs.archive.zip.JarDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme zip to file system driver: de.schlichtherle.truezip.fs.archive.zip.ZipDriver[charset=IBM437,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme zip.rae to file system driver: de.schlichtherle.truezip.fs.archive.zip.raes.SafeZipRaesDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot
KONFIG: Mapping scheme zip.raes to file system driver: de.schlichtherle.truezip.fs.archive.zip.raes.SafeZipRaesDriver[charset=UTF-8,federated=true,priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.socket.sl.IOPoolLocator$Boot
KONFIG: Located I/O pool service: de.schlichtherle.truezip.fs.file.TempFilePoolService[priority=0]
05.06.2011 16:04:03 de.schlichtherle.truezip.socket.sl.IOPoolLocator$Boot
KONFIG: Installing located I/O pool service: de.schlichtherle.truezip.fs.file.TempFilePoolService[priority=0]

Notice how the file system manager, some file system drivers and the I/O pool service are located and installed.

Enjoy TrueZIP!