de.micromata.genome.logging.spi.log4j.LRLLog4JLogging Maven / Gradle / Ivy
The newest version!
//
// Copyright (C) 2010-2016 Micromata GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package de.micromata.genome.logging.spi.log4j;
import java.sql.Timestamp;
import java.util.List;
import de.micromata.genome.logging.BaseLogging;
import de.micromata.genome.logging.LogAttribute;
import de.micromata.genome.logging.LogEntry;
import de.micromata.genome.logging.LogEntryCallback;
import de.micromata.genome.logging.LogWriteEntry;
import de.micromata.genome.logging.Logging;
import de.micromata.genome.util.types.Pair;
/**
* Loggs into secondaryLogging (by default Log4J) and keeps nth records in memory for viewing.
*
* This implemention does not work for cluster
*
* TODO synchronize
*
* @author roger
*
*/
public class LRLLog4JLogging extends BaseLogging
{
/**
* The max queue length.
*/
private int maxQueueLength = 2000;
/**
* The current syntetic pk.
*/
private long currentSynteticPk = 0;
/**
* The queue.
*/
private RoundList queue = new RoundList(maxQueueLength);
/**
* The secondary logging.
*/
private Logging secondaryLogging = new Log4JLogging();
/**
* Convert.
*
* @param lwe the lwe
* @return the log entry
*/
protected LogEntry convert(LogWriteEntry lwe)
{
LogEntry le = new LogEntry();
if (lwe.getTimestamp() != 0) {
le.setTimestamp(lwe.getTimestamp());
} else {
le.setTimestamp(System.currentTimeMillis());
}
le.setAttributes(lwe.getAttributes());
le.setCategory(lwe.getCategory());
// le.setDocLogEntry(lwe.get)
le.setLogLevel(lwe.getLevel());
le.setMessage(lwe.getMessage());
return le;
}
@Override
public void doLogImpl(LogWriteEntry lwe)
{
LogEntry le = convert(lwe);
le.setLogEntryIndex(++currentSynteticPk);
queue.add(le);
secondaryLogging.doLogImpl(lwe);
}
@Override
protected void selectLogsImpl(List