1 package net
.rizon
.acid
.logging
;
3 import ch
.qos
.logback
.classic
.Level
;
4 import ch
.qos
.logback
.classic
.spi
.ILoggingEvent
;
5 import ch
.qos
.logback
.classic
.spi
.IThrowableProxy
;
6 import ch
.qos
.logback
.classic
.spi
.StackTraceElementProxy
;
7 import ch
.qos
.logback
.core
.UnsynchronizedAppenderBase
;
8 import java
.util
.ArrayList
;
10 import net
.rizon
.acid
.core
.AcidCore
;
11 import net
.rizon
.acid
.core
.Acidictive
;
12 import net
.rizon
.acid
.core
.User
;
13 import net
.rizon
.acid
.util
.Format
;
15 public class Logger
extends UnsynchronizedAppenderBase
<ILoggingEvent
>
18 private String
calculateColor(Level level
)
20 switch (level
.toInt())
23 return Format
.color(Format
.GREY
);
27 return Format
.color(Format
.ORANGE
);
29 return Format
.color(Format
.RED
);
36 protected void append(ILoggingEvent event
)
38 Level level
= event
.getLevel();
39 if (!level
.isGreaterOrEqual(Level
.INFO
))
44 String message
= event
.getFormattedMessage();
45 IThrowableProxy throwable
= event
.getThrowableProxy();
46 StackTraceElement
[] stes
= null;
48 if (throwable
!= null)
50 List
<StackTraceElement
> list
= new ArrayList
<>();
51 for (StackTraceElementProxy step
: throwable
.getStackTraceElementProxyArray())
53 list
.add(step
.getStackTraceElement());
55 stes
= list
.toArray(new StackTraceElement
[0]);
58 if (AcidCore
.me
!= null && !AcidCore
.me
.isBursting() && User
.findUser(Acidictive
.conf
.general
.control
) != null)
60 String routingSpam
= Acidictive
.conf
.getChannelNamed("routing-spam");
64 Acidictive
.privmsg(routingSpam
, calculateColor(event
.getLevel()) + Format
.BOLD
+ event
.getLevel() + Format
.BOLD
+ Format
.color(0) + " (" + event
.getCallerData()[0].getFileName() + "): " + message
);
67 if (throwable
!= null)
69 String exception
= throwable
.getMessage() == null ? throwable
.getClassName() : throwable
.getMessage();
71 if (exception
!= null)
73 Acidictive
.privmsg(routingSpam
, exception
);
78 for (StackTraceElement ste
: stes
)
80 Acidictive
.privmsg(routingSpam
, ste
.toString());