Search in sources :

Example 1 with LoggerException

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);
}
Also used : lombok.val(lombok.val) LoggerException(oap.logstream.LoggerException) SneakyThrows(lombok.SneakyThrows)

Example 2 with LoggerException

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);
    }
}
Also used : Path(java.nio.file.Path) LoggerException(oap.logstream.LoggerException) CountingOutputStream(com.google.common.io.CountingOutputStream) IOException(java.io.IOException)

Example 3 with LoggerException

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");
}
Also used : Scheduled(oap.concurrent.scheduler.Scheduled) Metrics(oap.metrics.Metrics) lombok.val(lombok.val) LoggerException(oap.logstream.LoggerException) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) OPERATIONAL(oap.logstream.AvailabilityReport.State.OPERATIONAL) Scheduler(oap.concurrent.scheduler.Scheduler) AvailabilityReport(oap.logstream.AvailabilityReport) ToString(lombok.ToString) LoggerBackend(oap.logstream.LoggerBackend) Path(java.nio.file.Path) Closeables(oap.io.Closeables) FAILED(oap.logstream.AvailabilityReport.State.FAILED) LoggerException(oap.logstream.LoggerException) LoggerException(oap.logstream.LoggerException)

Aggregations

LoggerException (oap.logstream.LoggerException)3 Path (java.nio.file.Path)2 lombok.val (lombok.val)2 CountingOutputStream (com.google.common.io.CountingOutputStream)1 IOException (java.io.IOException)1 TimeUnit (java.util.concurrent.TimeUnit)1 SneakyThrows (lombok.SneakyThrows)1 ToString (lombok.ToString)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Scheduled (oap.concurrent.scheduler.Scheduled)1 Scheduler (oap.concurrent.scheduler.Scheduler)1 Closeables (oap.io.Closeables)1 AvailabilityReport (oap.logstream.AvailabilityReport)1 FAILED (oap.logstream.AvailabilityReport.State.FAILED)1 OPERATIONAL (oap.logstream.AvailabilityReport.State.OPERATIONAL)1 LoggerBackend (oap.logstream.LoggerBackend)1 Metrics (oap.metrics.Metrics)1