package tw.kewang.redmine.appender;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import com.taskadapter.redmineapi.IssueManager;
import com.taskadapter.redmineapi.RedmineException;
import com.taskadapter.redmineapi.RedmineManager;
import com.taskadapter.redmineapi.RedmineManagerFactory;
import com.taskadapter.redmineapi.bean.Issue;
import com.taskadapter.redmineapi.bean.IssueFactory;

public class RedmineAppender extends AppenderBase<ILoggingEvent> {
    private String url;
    private String apiKey;
    private RedmineManager redmineManager;
    private IssueManager issueManager;

    @Override
    public void start() {
        String propertyRedmineUrl = getContext().getProperty("REDMINE_URL");
        String propertyRedmineApiKey = getContext().getProperty("REDMINE_API_KEY");

        if (propertyRedmineUrl == null || propertyRedmineUrl.length() == 0 || propertyRedmineApiKey == null
                || propertyRedmineApiKey.length() == 0) {
            System.out.println("No set REDMINE_URL / REDMINE_API_KEY");

            return;
        }

        url = propertyRedmineUrl;
        apiKey = propertyRedmineApiKey;
        redmineManager = RedmineManagerFactory.createWithApiKey(url, apiKey);
        issueManager = redmineManager.getIssueManager();

        super.start();
    }

    @Override
    public void append(ILoggingEvent event) {
        createIssue(event);
    }

    private void createIssue(ILoggingEvent event) {
        Issue issue = IssueFactory.create(22, event.getLoggerName());

        issue.setDescription(event.getFormattedMessage());

        try {
            issueManager.createIssue(issue);
        } catch (RedmineException e) {
            e.printStackTrace();
        }
    }
}
@@ -541,24 +541,51 @@
 ing apiKey;%0A
+    private int projectId;%0A
     private 
@@ -848,33 +848,32 @@
 MINE_API_KEY%22);%0A
-%0A
         if (prop
@@ -869,11 +869,11 @@
    i
-f (
+nt 
 prop
@@ -887,88 +887,207 @@
 mine
-Url == null %7C%7C propertyRedmineUrl.length() == 0 %7C%7C propertyRedmineApiKey == null
+ProjectId = -1;%0A%0A        try %7B%0A            propertyRedmineProjectId = Integer.valueOf(getContext().getProperty(%22REDMINE_PROJECT_ID%22));%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();
 %0A   
@@ -1091,24 +1091,27 @@
         
+%7D%0A%0A
         
 %7C%7C prope
@@ -1106,46 +1106,94 @@
     
-%7C%7C propertyRedmineApiKey.length() == 0
+if (checkProperty(propertyRedmineUrl, propertyRedmineApiKey, propertyRedmineProjectId)
 ) %7B%0A
@@ -1256,24 +1256,45 @@
 MINE_API_KEY
+ / REDMINE_PROJECT_ID
 %22);%0A%0A       
@@ -1387,24 +1387,70 @@
 mineApiKey;%0A
+        projectId = propertyRedmineProjectId;%0A
         redm
@@ -1599,24 +1599,355 @@
 t();%0A    %7D%0A%0A
+    private boolean checkProperty(String propertyRedmineUrl, String propertyRedmineApiKey, int propertyRedmineProjectId) %7B%0A        return propertyRedmineUrl == null %7C%7C propertyRedmineUrl.length() == 0 %7C%7C propertyRedmineApiKey == null%0A                %7C%7C propertyRedmineApiKey.length() == 0 %7C%7C propertyRedmineProjectId == -1;%0A    %7D%0A%0A
     @Overrid
@@ -2127,10 +2127,17 @@
 ate(
-22
+projectId
 , ev

Add REDMINE_PROJECT_ID