Skip to content

Commit 1a5a53d

Browse files
xjaspreetsandhujenkins
authored andcommitted
[Loglens] Add overrideFatalWithError flag to LoglensAppender
**Problem**: There is an inconsistency in the way a `FileAppender` and a `LoglensHandler` produce levels for log records. - LoglensHandler and LoglensFormatter use the `java.util.logging` package to build log records and transform them to `com.twitter.logging`, where the level `ERROR`/`SEVERE` is enumerated to be equivalent to level `FATAL`. - Conversely, a FileAppender uses the `ch.qos.logback` package to produce records, where events with level `ERROR` are not transformed, and are written directly. **Solution**: Add a flag for users to include in their `logback.xml` file to optionally override `FATAL` logs with the `ERROR` level, so that records sent to file and those sent to ClickHouse are consistent. Differential Revision: https://phabricator.twitter.biz/D1250623
1 parent 33effb4 commit 1a5a53d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

util-logging/src/main/scala/com/twitter/logging/Formatter.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
package com.twitter.logging
1818

1919
import com.twitter.util.TwitterDateFormat
20-
import java.text.{MessageFormat, DateFormat}
20+
import java.text.MessageFormat
21+
import java.text.DateFormat
2122
import java.util.regex.Pattern
22-
import java.util.{Date, GregorianCalendar, TimeZone, logging => javalog}
23+
import java.util.Date
24+
import java.util.GregorianCalendar
25+
import java.util.TimeZone
26+
import java.util.{logging => javalog}
2327
import scala.collection.mutable
2428
import java.{util => ju}
2529

@@ -125,14 +129,15 @@ class Formatter(
125129
/**
126130
* Return the string representation of a given log level's name
127131
*/
128-
def formatLevelName(level: javalog.Level): String = {
132+
def formatLevelName(level: javalog.Level, overrideFatalWithError: Boolean = false): String = {
129133
level match {
130134
case x: Level =>
131135
x.name
132136
case x: javalog.Level =>
133137
Logger.levels.get(x.intValue) match {
134138
case None => "%03d".format(x.intValue)
135-
case Some(level) => level.name
139+
case Some(level) =>
140+
if (level == Level.FATAL && overrideFatalWithError) "ERROR" else level.name
136141
}
137142
}
138143
}

0 commit comments

Comments
 (0)