java - can we have level based log files using log4j -
I created an application using log4j to store all the level based logs in a file, but in the current state The single file will keep all the level logs, such as ALL, INFO, ERROR, FATAL, WARN, DEBUG etc. ... because in my application I am saying an option on which there is a select box on which I select the error I should only show error log, if I select the notification Shall be only information log.
I am parsing the log file to get the proper log based on a specific level, but in this situation, if the log file is too large, it will take longer.
A solution for which I have thought that to maintain log files for each level, so that we can avoid touching them
Know everyone's idea on this. However, if it is okay we can login the APRR log to differentiate log-in log logs, log in the APIs, login to the APIO, log in the inputs, and have a normal log to keep all the level based logs File
My log4j.properties is given below
# log4j configuration log4j.rootLogger = debug, Appender1, Appender2 log4j.appender.Appender1 = Org.apache.log4j ConsoleAppender log4j.appender.Appender1.layout = org.apache.log4j.PatternLayout log4j.appender.Appender1.layout.ConversionPattern =% d [% T]% -7p% 10c {1} -% m% n log4j.appender.Appender2 = Orgkapacheklog4jkfilippender Log4jkappenderkappender2kfail = $ {} Apprutpath /veb-inf/logs/logdemosklog Log4jkappenderkappender2kleaut = Orgkapacheklog4jkptternlyut Log4jkappenderkappender2 Outout. The conversion pattern =% d [% t]% -7p% 10c {1} -% m% n The parsing method is shown below
Scanner Scanner = New Scanner (New File (ctx.getRealPath ("/") "" / WEB-INF / Log / Logdomos. Log) "); While (scanner.hasNext ()) {string level = request.getParameter ("level"); String log = scanner. NXtine (); String regex = "(\\ d {4} - \\ d {2} - \\ d {2}) (\\ d {2}: \\ d {2}: \\ d {2}, \\ D {3}) \\ [(. *) \\] ([^] *) + ([^] *) - (. *) $ "; Pattern p = Pattern.compile (regex); Matter M = P. Dead (log); If (m.matches () & amp; amp; amp; amp; amp; amp; amp; group & quot;) == 6) {string date = m.group (1); String Time = MG Group (2); String Thread ID = m.group (3); String preference = m.group (4); String category = m.group (5); String message = m.group (6); If (priority) is (equal to). System.out.println ("Date:" + Date); System.out.println ("time:" + time); System.out.println ("Thread ID:" + Thread ID); System.out.println ("Priority:" + priority); System.out.println ("Category:" + Category); System.out.println ("Message:" + Message); } And {logslist.ed (log); }}} Session.setAttribute ("logs", logs list); Scanner.close (); After the text "itemprop =" text "> after you use
for information as follows (< Can / code> and error ): # log4j configuration log4j.rootLogger = debug, OnlyInfo, OnlyError # information only log4j.appender.OnlyInfo = org Apache.log4j FileAppender log4j.appender.OnlyInfo.File = $ {appRootPath} /WEB-INF/logs/info.log log4j.appender.OnlyInfo.File = log / info.log log4j.appender.OnlyInfo.layout = org.apache.log4j. PatternLayout log4j.appender.OnlyInfo.layout.ConversionPattern =% d [% T]% -7p% 10c {1} -% m% n log4j.appender.OnlyInfo.filter.A = org.apache.log4j.varia.LevelRangeFilter log4j .appender.OnlyInfo.filter.A.LevelMin = information log4j.appender.OnlyInfo.filter.A.LevelMax = information log4j.appender.OnlyInfo.filter.A.AcceptOnMatch = true # only error log4j.appender.OnlyError = org.apache Klog4jkfilippender Log4jkappenderkonlyerrorkfail = $ {} Apprutpath /veb-inf/logs/arrklog Log4jkappenderkonlyerrorkleaut = Orgkapacheklog4jkptternlyut Log4jkappenderkonlarro Rkleaut. ConversionPattern =% d [% T]% -7p% 10c {1} -% m% n log4j.appender.OnlyError.filter.A = org.apache.log4j.varia.LevelRangeFilter log4j.appender.OnlyError Filter.A.LevelMin = Error log4j.appender.OnlyError.filter.A.LevelMax = Error log4j.appender.OnlyError.filter.A.AcceptOnMatch = True
Comments
Post a Comment