Welcome back. So let's add one more feature. And this time it's gonna be
a feature for our logged in users.
We want them to be able to view their own personal logs.
So this is gonna be in two steps. First, we'll have to create a function
that would allow them to view their logs. And then second,
we'll have to create a post login menu.
So I log in users, they will have a separate menu where
they will have the option to view the log. So this is going to be in two parts.
First of all, let us create a function
that would allow them to view the log. So
I'm gonna do that just underneath the main login function.
So let me just add a note in here that says uh
function,
uh sorry function
to view logs. OK?
I'm gonna call this function view
on those call logs.
And of course, we're gonna pass in the
parameter user name.
OK? At my colon. All right.
So let's first of all print out like
a general message saying something like you know,
logs for user and then
you know the particular user. So
I'm gonna say print.
Ok. And then
let's have our F string and then let's have our coats
and then let me add my backward slash and, and then we can say logs for
a
user
and then
we have a curly braces
and then we can have the user name.
Ok. Not necessary, but it's nice to have. All right. Now,
we're gonna open up the audit log, the text file because it's from there.
We're gonna pull in the logs. So I'm gonna say with,
and now open
and now in brackets, what's the name of the file?
It is audit underscore log
dot
txt.
And now, of course, we want to have
the read mode,
ok? Because we're going to read from the file
and we're gonna say as log underscore file
at our colon.
And, ok, so now we're gonna go through the logs and the files,
let's pass them into a variable called logs.
And now log underscore file dot red lines.
Ok? And there it is.
Ok.
So now we're gonna have to create some sort of
a for loop that's gonna go through each individual logs.
And what exactly are we looking for?
We are looking for any logs that will match a particular user name.
So I'm gonna come in here right now.
All right. And I'm gonna say,
uh,
user logs,
ok. User
underscore logs
is gonna be equal
to and now check this out. I'm gonna open up at
my brackets in here, I'm gonna say log dot strip.
And the reason why I'm using the strip function is again,
I want to remove any unnecessary
white space or margins from the user names. So I'm gonna say log the strip and now
I'm gonna say for
log in logs.
So especially for each individual log in our logs.
And what are we looking for looking for if the user name
is in the log? So we're looking for a very specific username in our log files.
So now if we do in fact find
a match for the log for the username or do we now do. So we're gonna say
if user
underscore logs
add a colon
and now I'm gonna say four log in
user
on those call logs, what we wanna do, we simply want to print.
So I'm gonna say print and then
log
and there you go. And of course, we need to create a condition.
What if no log was found?
We can simply say else
and now we can print,
we can say
no logs were found
in your account because remember this is for the logged in user
and there you go. So just to give you a very quick recap.
All right, we defined the function as view on those logs
and we passed in the username
and now we printed out a general message saying, you know, logs for the user
and then the username.
And then we opened up the audit log, the TXT file,
we're going to read from it as a log file.
And then we created a available called logs
that will actually use the method with lines for each particular log file.
And now in here, we created our for loop
that's going to go through each individual log in the logs
and then see if there is a match for that user name.
Now, if there is in fact a match,
we can simply print out the log for that particular user.
Otherwise
we will simply say no logs are found in their account.
So there it is, we have successfully created a function to view the logs.
Join me in the next video where we're gonna create
the post login menu for our logged in users.