richard.herbert
08/16/2022, 3:15 PMLogbox
file appender I thought I'd rustle up my own layout, simples?
So I've created my custom layout and referenced it in config and all's well...
...except I'm having trouble replicating, as a first pass, the default format.
The appender name doesn't appear to available via the LogEvent
object and I can't seem to use the severityToString()
helper.
Also I'd like to control the first row, csv column names, but not sure how to replace that line.
Thought or further read suggestions welcome.bdw429s
08/16/2022, 3:20 PMbdw429s
08/16/2022, 3:21 PMif ( hasCustomLayout() ) {
entry = getCustomLayout().format( loge );
} else {
// Cleanup main message
if ( len( loge.getExtraInfoAsString() ) ) {
message = message & " | ExtraInfo:" & loge.getExtraInfoAsString();
}
message = replace( message, """", """""", "all" );
message = replace( message, "#chr( 13 )##chr( 10 )#", " ", "all" );
message = replace( message, chr( 13 ), " ", "all" );
// Entry string
entry = """#severityToString( logEvent.getSeverity() )#"",""#getname()#"",""#dateFormat( timestamp, "mm/dd/yyyy" )#"",""#timeFormat( timestamp, "HH:mm:ss" )#"",""#loge.getCategory()#"",""#message#""";
}
so if you put what 's in the second half of that if in your custom layout, you'll have the default layoutbdw429s
08/16/2022, 3:26 PMgetExtraInfoAsString()
on the log event object, so inside your custom layout, it would be loge.getExtraInfoAsString()
, etc.bdw429s
08/16/2022, 3:27 PMbdw429s
08/16/2022, 3:28 PMThe appender name doesn't appear to available via theI'm curious what you mean here. Are you wanting to know if your custom appender was called from aobjectLogEvent
FileAppender
, RollingFileAPpender
, etc? Generally speaking, that should be none of its concern.bdw429s
08/16/2022, 3:29 PMrichard.herbert
08/16/2022, 3:37 PMFileAppender
so I guess I could make my own appender by copying the existing and change it to meet my needs. It should really have an ExtraInfo
entry to support that from debug()
etc.
Category name is fine, I can get that from #logEvent.getCategory()#
, it's the appender name I can't reach. I guess that's a mute point, I could just hardcode it in my return string.
I did have #severityToString( logEvent.getSeverity() )#
in my layout but that seems to fails. I'm not sure how that method makes it's way into the layout?bdw429s
08/16/2022, 3:41 PMbdw429s
08/16/2022, 3:41 PM/**
* convert a severity to a string
*
* @severity The severity to convert to a string
*/
function severityToString( required numeric severity ){
return this.logLevels.lookup( arguments.severity );
}
bdw429s
08/16/2022, 3:42 PMrichard.herbert
08/16/2022, 3:50 PMLogbox
- thanks for the insight.bdw429s
08/16/2022, 4:04 PMrichard.herbert
08/16/2022, 4:08 PMbdw429s
08/16/2022, 4:09 PMbdw429s
08/16/2022, 4:10 PMrichard.herbert
08/16/2022, 4:14 PM