public class Crunchlog extends Object
The Crunchlog manages a directory stucture where all submitted records are stored in compressed files. These contain a JSON object per line which represents the map that was submitted. Being a map, records with varying attributes can be stored. The crunchlog will start a file per day, and limit the file size to a sane value (10 MB). Being JSON files, processing of the generated files is quite easy. The files are compressed as JSON contains a lot of reoccuring elements. Also many attribute names will be used frequently.
The implementation of the Crunchlog is put into CrunchlogKernel
as some frameworks which require public
methods are utilized.
The Crunchlog contains some safety switches to disable itself if either no valid base directory is present or if the underlying disk runs out of free space.
Note that crunchlog files older than one year are deleted by DeleteOldCrunchlogs
. If files need to be kept
longer, collectAllCompletedFiles(Consumer)
can be invoked to collect all available files and store them in
a permanent location. The given consumer may also delete the files by itself, to free up disk space.
To disable the crunchlog entirely, set frameworks.crunchlog = false in the system config.
Modifier and Type | Class and Description |
---|---|
class |
Crunchlog.LogBuilder
Creates a new builder for a log entry in the crunchlog.
|
Modifier and Type | Field and Description |
---|---|
static String |
FIELD_DATE
This field will be automatically added to each record, containing the timestamp when is was logged.
|
static String |
FIELD_TYPE
It is highly recommended to add a value for this field in each record to better support filtering for
similar events.
|
protected static sirius.kernel.health.Log |
LOG |
Constructor and Description |
---|
Crunchlog() |
Modifier and Type | Method and Description |
---|---|
void |
collectAllCompletedFiles(Consumer<File> fileProcessor)
Iterates over all completely written files (excluding the one currently being written to).
|
Crunchlog.LogBuilder |
log(String event)
Creates a new builder to create a log message using fluid method calls.
|
void |
safeLog(String event,
sirius.kernel.commons.Callback<Crunchlog.LogBuilder> log)
Implements a safe way of logging to the crunchlog.
|
void |
submit(sirius.kernel.commons.Context data)
Submits a record to the crunchlog which will be eventually persisted to disk.
|
protected static final sirius.kernel.health.Log LOG
public static final String FIELD_DATE
public static final String FIELD_TYPE
@CheckReturnValue public Crunchlog.LogBuilder log(String event)
Consider using safeLog(String, Callback)
to perform logging in a critical section.
event
- the event name to logpublic void safeLog(String event, sirius.kernel.commons.Callback<Crunchlog.LogBuilder> log)
As the crunchlog might be involved in critical operations, where a failure during logging must to abort the
actual operation, this method creates (and submits) a Crunchlog.LogBuilder
while surrounding all calls
with a try / catch block, which logs all errors, but does not throw an exception.
event
- the event to loglog
- the consumer to actually apply the loggingpublic void submit(sirius.kernel.commons.Context data)
data
- the record to persistpublic void collectAllCompletedFiles(Consumer<File> fileProcessor)
This could be used to upload all files to another repository for further processing. The consumer may delete the files to better manage disk usage.
fileProcessor
- a consumer which will be supplied with all completely written files of the CrunchlogCopyright © 2018. All rights reserved.