Hello and welcome back to the next level. In our exorcism elixir track. We're going to be tackling the log level now, which is going to focus on atoms and using the cond um guess conditional, even though it stands for conditional. Um So let's go ahead and get started. I've already downloaded the um level over to my code base which is attached to the player for you guys. So you're running a system that consists of a few applications producing many logs. You want to write a small program that will aggregate those logs and give them labels according to their severity level. All applications in your system use the same log codes but some of the legacy applications don't support all the codes. Alright, so implement log level to label function. It should take into your code and a boolean flag telling you if the log comes from a legacy app and return the label of a log line as an atom. So this the label of the log line. So this is each of the lines here and it's gonna return to the atom there to return this label as an atom. Unknown law codes and codes unsupported and legacy apps to return an unknown label. Okay, so we're gonna be working with Cond um so let's go ahead and get started here. So what we're gonna do is we're gonna be receiving just pull up the chart here. So you'll be receiving a log code and whether or not it's supported in legacy. So I'm gonna actually just do our condition als in order of the numbers there. So let's go ahead and define con do we have our end and we're gonna do we're gonna take the level and say is it equal to zero And zero is not supported in legacy apps? So we're gonna say and not legacy question which is gonna mean and false essentially. And if so it's going to return trace which is that first label there? So the next four there are all positive legacy apps. So for these ones we can just do simply the level and then the label as an atom. So that number one is debug. We can do level is equal to one. We don't need to check vest because it's going to be we will have a condition that if it's not positive so and X levels equal to so do Oh I think yeah and then warning an error Level is equal to three morning. It was equal to four. Ever. Alright. And then number five is our fatal which is not supported and then are unknown which will go over in a second. So level is equal to five and not legacy tricks then. So for working with conditional we want if no path evaluates to true it's gonna be an error is raised by the runtime. So we want to make our last conditional just evaluate to true. So if it all of these fail whatever this version is there is going to pass so we're gonna say true. We need to return. No. Perfect. So now we can do mixed test. Uh log perfect. So two all of our labels to label ones have passed correctly so we can move on to the second which is to alert the recipient there. So let's go back and send alerts. So somebody has to be notified when unexpected things happen. Implement the alert recipient function to determine to whom the alert needs to be sent. The function should take it into your code and a boolean flag telling you if the law comes from a legacy app so it's gonna take the same two parameters that are first one our first function took it's gonna return the name of the recipient as an atom. Um and then it gives us the information there. So the first thing that I'm actually gonna do here is I'm gonna set up, I'm gonna use this first function to determine our output because it's gonna say if the log label is error fatal. Send it here. So I want to know what our output is gonna be. So we're gonna define label as being to label and we're gonna take in the level and the like I cannot type in the legacy. Now we're gonna do another cond and now we're going to do the label and then we can define our condition for what we're looking for there. So it says if the label is error or fatal. Send the alert to the ops team. So we'll deal there. Listen to ops table is equal to fatal. We're gonna send to okay. Ops You receive a log with an unknown label from a legacy system, send the alert to the Dev one team. Other unknown labels should be sent to the dev to team. So if you receive a log with an unknown label from a legacy system. So let's do label is equal to unknown and legacy Just to have that one. That's fun. Otherwise if the label is just okay Unknown too. That too, all other labels can be safely ignored. Um And they're returning this is false. It looks like. So let's just do a reel us. Perfect. So all of our tests went ahead and passed there. So simple way to just use the con there. Um I hope that made sense. It was a pretty straightforward exercise. Um And I will go ahead and see you in the next one.