I have an app which processes the JBOSS logs. It retrieves the active users of the application. Log has lines where it tell which user requested which operation.
the lines in log are like this:
[23 apr 2015 17:14:58,268] [INFO ] [Module: Search (845903)] -- Request is performing by User 'BILL GATES' using the 'App Session' Session
log files is big. ~1mb. many lines. not each of them refers to the user actions. What I do now is read the file LINE by LINE finding the one which has "User" string in it and then retrieve the name from that line.
It works. But - it's slow and it seems pretty heavy on the performance. I'm processing 5+ log files like this.
I'm looking in how can this be done better\faster? RegEx? any suggestions?
Thank you!
Update: code
If System.IO.File.Exists(tmpusr063) = True Then
Dim objReader As New System.IO.StreamReader(tmpusr063)
Do While objReader.Peek() <> -1
'Get the timestamp from the line
TextLine = objReader.ReadLine()
time = Microsoft.VisualBasic.Left(TextLine, 21)
time = Microsoft.VisualBasic.Right(time, 20)
tm = DateTime.ParseExact(time, "dd MMM yyyy HH:mm:ss", CultureInfo.CreateSpecificCulture("nl-NL"))
span = DateTime.Now.TimeOfDay - tm.TimeOfDay
' end of getting the timestamp in a Time type. span - is a difference between NOW and when the time on the line
If CInt(span.Hours) < user4timeh Then 'if the time of the line is withing the limits i set in hours
If CInt(span.Minutes) < user4timem Then ' in minutes then start disassembling the line
If TextLine.Contains("User") And TextLine.Contains("'") Then ' if line contains User = line has a username
linsplt = TextLine.Split("'") 'retrieving the user name
If users.Contains(linsplt(1)) = False Then
users(usrnmbr) = linsplt(1) 'assemble an array of user names
usrnmbr += 1
End If
End If
End If
End If
Loop
objReader.Close()
End If
BUT! i think i found a culprit.... the log has lots of line and i don't need those where "User" doesn't exist. but in my logic - i still take EACH line and retrieve time from it and only then check if it's a relevant line for the user name to be in...... damn:) i will move the if
statement up:) Not smart:)