use of oap.logstream.LoggerException in project oap by oaplatform.
the class DiskLoggerBackend method log.
@Override
@SneakyThrows
public void log(String hostName, String fileName, byte[] buffer, int offset, int length) {
if (closed) {
val exception = new LoggerException("already closed!");
listeners.fireError(exception);
throw exception;
}
Metrics.measureCounterIncrement(Metrics.name(METRICS_LOGGING_DISK).tag("from", hostName));
Metrics.measureHistogram(Metrics.name(METRICS_LOGGING_DISK_BUFFERS).tag("from", hostName), length);
String fullFileName = useClientHostPrefix ? hostName + "/" + fileName : fileName;
Writer writer = writers.get(fullFileName);
log.trace("logging {} bytes to {}", length, writer);
writer.write(buffer, offset, length, this.listeners::fireError);
}
use of oap.logstream.LoggerException in project oap by oaplatform.
the class Writer method write.
public synchronized void write(byte[] buffer, int offset, int length, Consumer<String> error) throws LoggerException {
try {
refresh();
Path filename = filename();
if (out == null)
if (Files.isFileEncodingValid(filename))
out = new CountingOutputStream(IoStreams.out(filename, Encoding.from(ext), bufferSize, true));
else {
error.accept("corrupted file, cannot append " + filename);
log.error("corrupted file, cannot append {}", filename);
Files.rename(filename, logDirectory.resolve(".corrupted").resolve(logDirectory.relativize(filename)));
out = new CountingOutputStream(IoStreams.out(filename, Encoding.from(ext), bufferSize));
}
log.trace("writing {} bytes to {}", length, this);
out.write(buffer, offset, length);
} catch (IOException e) {
log.error(e.getMessage(), e);
try {
closeOutput();
} finally {
out = null;
}
throw new LoggerException(e);
}
}
use of oap.logstream.LoggerException in project oap by oaplatform.
the class SocketLoggerBackend method send.
public synchronized void send() {
if (!closed)
try {
if (buffers.isEmpty())
loggingAvailable = true;
refreshConnection();
log.debug("sending data to server...");
buffers.forEachReadyData(buffer -> {
if (!sendBuffer(buffer)) {
log.debug("send unsuccessful...");
refreshConnection();
return sendBuffer(buffer);
}
return true;
});
log.debug("sending done");
} catch (Exception e) {
loggingAvailable = false;
listeners.fireError(new LoggerException(e));
log.warn(e.getMessage());
log.trace(e.getMessage(), e);
Closeables.close(connection);
}
if (!loggingAvailable)
log.debug("logging unavailable");
}
Aggregations