Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/bark/client/examples/AlertWebhook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package bark.client.examples;

import bark.client.constants.Global;
import bark.client.models.BarkLog;
import bark.client.models.Config;
import bark.client.models.Webhook;

import java.io.IOException;

import static bark.client.models.Config.BarkClient;

public class AlertWebhook {
public static void main(String[] args) throws IOException {
Config logConf = BarkClient("http://localhost:8080/", Global.Info, "AlertWebhookSvc", "AlertWebhookSess");
Webhook webhook = new Webhook() {
@Override
public void processWebhook(BarkLog barkLog) {
System.out.println(barkLog.toString());
}
};

logConf.setAlertWebhook(webhook);
logConf.Alert("Hello Alert Webhook");
}
}
14 changes: 13 additions & 1 deletion src/main/java/bark/client/models/BarkLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,17 @@ public void setMoreData(MoreData moreData) {
this.moreData = moreData;
}


@Override
public String toString() {
return "BarkLog{" +
"id=" + id +
", logTime=" + logTime +
", logLevel='" + logLevel + '\'' +
", serviceName='" + serviceName + '\'' +
", sessionName='" + sessionName + '\'' +
", code='" + code + '\'' +
", message='" + message + '\'' +
", moreData=" + moreData +
'}';
}
}
10 changes: 10 additions & 0 deletions src/main/java/bark/client/models/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class Config {
private String errorLevel;
private String serviceName;
private String sessionName;
private Webhook webhook;

public void setAlertWebhook(Webhook webhook){
this.webhook = webhook;
}

public void Panic(String message) throws IOException {
System.out.println(message);
Expand All @@ -21,6 +26,11 @@ public void Panic(String message) throws IOException {
public void Alert(String message) throws IOException {
System.out.println(message);
BarkLog log = new BarkLog(Global.Alert, this.serviceName, this.sessionName, Global.DefaultLogCode,message);

if(webhook!=null){
webhook.processWebhook(log);
}

dispatchLogMessage(log);
}
public void Error(String message) throws IOException {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/bark/client/models/Webhook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bark.client.models;

public interface Webhook {
void processWebhook(BarkLog log);
}