use of com.peterphi.servicemanager.service.logging.LogLineTableEntity in project stdlib by petergeneric.
the class LogSerialiser method toJson.
public String toJson(final Collection<LogLineTableEntity> results) {
try {
StringWriter sw = new StringWriter(4096);
JSONWriter w = new JSONWriter(sw);
w.array();
for (LogLineTableEntity line : results) write(w, line);
w.endArray();
return sw.toString();
} catch (JSONException e) {
throw new RuntimeException("Error serialising lines to JSON: " + e.getMessage(), e);
}
}
use of com.peterphi.servicemanager.service.logging.LogLineTableEntity in project stdlib by petergeneric.
the class AzureLogStore method storeAsBatch.
@Retry
public void storeAsBatch(final List<LogLineTableEntity> lines) throws StorageException {
if (lines.isEmpty())
// nothing to do!
return;
TableBatchOperation operation = new TableBatchOperation();
for (LogLineTableEntity line : lines) {
if (log.isTraceEnabled())
log.trace("Storing entity with partition=" + line.getPartitionKey() + ", row=" + line.getRowKey());
operation.insertOrReplace(line);
}
logdata.execute(operation);
}
use of com.peterphi.servicemanager.service.logging.LogLineTableEntity in project stdlib by petergeneric.
the class FileLogStore method store.
@Override
public synchronized void store(List<LogLineTableEntity> lines) throws RuntimeException {
if (System.currentTimeMillis() > timestampForNextFile) {
// Close the existing file
IOUtils.closeQuietly(currentFile);
currentFile = null;
try {
FileWriter fw = new FileWriter(new File(storePath, LocalDate.now().toString() + ".log"), true);
currentFile = fw;
} catch (IOException e) {
throw new RuntimeException("Error opening new log file! " + e.getMessage(), e);
}
// Get the timestamp for the start of tomorrow
timestampForNextFile = LocalDate.now().plusDays(1).toDateTimeAtStartOfDay().getMillis();
}
// Now append all the logs
for (LogLineTableEntity line : lines) {
try {
currentFile.append(format(line));
} catch (IOException e) {
throw new RuntimeException("Error appending log line " + line + " to log file! " + e.getMessage(), e);
}
}
try {
currentFile.flush();
} catch (IOException e) {
// ignore
}
}
use of com.peterphi.servicemanager.service.logging.LogLineTableEntity in project stdlib by petergeneric.
the class ServiceManagerUIServiceImpl method doSearchLogs.
@Override
public Response doSearchLogs(String fromStr, String toStr, String filter) {
// TODO take into account the user's timezone!
DateTime from = DateTime.parse(fromStr).withZone(LONDON);
// TODO take into account the user's timezone!
DateTime to = DateTime.parse(fromStr).withZone(LONDON);
final List<LogLineTableEntity> results = logStore.search(from, to, filter);
return Response.ok().type(MediaType.APPLICATION_JSON_TYPE).entity(serialiser.toJson(results)).build();
}
use of com.peterphi.servicemanager.service.logging.LogLineTableEntity in project stdlib by petergeneric.
the class ServiceManagerLoggingRestServiceImpl method report.
@Override
public void report(final LogReport logs) {
if (log.isTraceEnabled())
log.trace("Received " + logs.getLines().length + " log lines to store");
try {
final ServiceInstanceEntity serviceInstance = cache.get(logs.getServiceId());
// Make sure that all store calls are for the same partition (date + instance id)
// This is technically only a requirement for Azure but it's a guarantee other
// stores can use effectively (e.g. writing to datestamped log files)
String partitionKey = null;
List<LogLineTableEntity> pending = new ArrayList<>();
for (LogLine line : logs.getLines()) {
LogLineTableEntity entity = convert(serviceInstance, line);
if (partitionKey == null) {
// First entry in a new partition
partitionKey = entity.getPartitionKey();
} else if (!partitionKey.equals(entity.getPartitionKey())) {
// Flush all the lines up til now and then start a new list
service.store(pending);
pending = new ArrayList<>();
partitionKey = entity.getPartitionKey();
}
pending.add(entity);
}
// Make sure we flush any remaining data to the storage system
service.store(pending);
} catch (Throwable t) {
log.error("Error saving logs", t);
throw t;
}
}
Aggregations