[
https://issues.apache.org/jira/browse/LOG4J2-1741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15760862#comment-15760862
]
Mikael Ståldal commented on LOG4J2-1741:
----------------------------------------
I just tried to write a simple appender in Scala, and it worked without
problems:
{code}
import org.apache.logging.log4j.core.appender.AbstractAppender
import org.apache.logging.log4j.core.config.plugins.{Plugin, PluginAttribute,
PluginElement, PluginFactory}
import org.apache.logging.log4j.core.{Filter, Layout, LogEvent}
@Plugin(name = "Scala", category = "Core", elementType = "appender",
printObject = true)
class ScalaAppender private(val name: String, val filter: Filter, val layout:
Layout[_ <: Serializable]) extends AbstractAppender(name, filter, layout) {
def append(event: LogEvent): Unit = {
print("scala: " + new String(getLayout.toByteArray(event)))
}
}
object ScalaAppender {
@PluginFactory
def createAppender(@PluginAttribute("name") name: String,
@PluginElement("Layout") layout: Layout[_ <:
Serializable],
@PluginElement("Filters") filter: Filter
): ScalaAppender = {
new ScalaAppender(name, filter, layout)
}
}
{code}
Can you post some code of a non-working Scala appender?
> scala: add support for creating custom plugins
> ----------------------------------------------
>
> Key: LOG4J2-1741
> URL: https://issues.apache.org/jira/browse/LOG4J2-1741
> Project: Log4j 2
> Issue Type: Improvement
> Components: Plugins
> Reporter: PJ Fanning
>
> I tried to add a custom appender using Scala but the pattern of having a
> class with an Plugin annotation and a static method on that class with a
> PluginFactory or PluginBuilderFactory annotation doesn't seem to work in
> Scala.
> In Scala, you can create a companion object to a class where you can
> implement the equivalent of static methods but these are not the same class
> under the hood. The Scala compiler builds 2 or more classes, the companion
> object gets a class name with a $ appended to it. I think this is affecting
> the lookup for the method with the Factory annotation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]