All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cubeengine.logscribe.target.EmailTarget Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package org.cubeengine.logscribe.target;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import org.cubeengine.logscribe.LogEntry;
import org.cubeengine.logscribe.LogTarget;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;

public class EmailTarget extends LogTarget
{
    private final Function mapper;

    public EmailTarget(Function mapper)
    {
        this.mapper = mapper;
    }

    // TODO implement me
    @Override
    protected void publish(LogEntry entry)
    {
        Email mail = this.mapper.apply(entry);
        CompletableFuture.runAsync(() -> {
            try
            {
                mail.send();
            }
            catch (EmailException e)
            {
                throw new LogTargetException(e);
            }
        });
    }

    @Override
    protected void onShutdown()
    {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy