Skip to content

Commit 59a3659

Browse files
authored
Log Levels concept exercise (#459)
* Log Levels concept exercise * incorporate reviewer comments
1 parent abf3e1e commit 59a3659

9 files changed

Lines changed: 572 additions & 0 deletions

File tree

config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@
104104
],
105105
"status": "wip"
106106
},
107+
{
108+
"slug": "log-levels",
109+
"name": "Log Levels",
110+
"uuid": "6c85ef11-cd2d-4718-9f75-84c467afb2f9",
111+
"concepts": [
112+
"strings"
113+
],
114+
"prerequisites": [
115+
"vectors"
116+
],
117+
"status": "wip"
118+
},
107119
{
108120
"slug": "mixed-juices",
109121
"name": "Mixed Juices",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Hints
2+
3+
## General
4+
5+
- Knowledge of regular expressions is not required or expected for this exercise.
6+
- However, students who already have regex experience are free to use it if they wish.
7+
8+
## 1. Get message from a log line
9+
10+
- Think about how to split the log line into useful parts.
11+
- You may need to remove excess whitespace.
12+
13+
## 2. Get log level from a log line
14+
15+
- There are various ways to pull out the desired substring, but position index may be the most basic.
16+
- Remember to change case.
17+
18+
## 3. Reformat a log line
19+
20+
- You already wrote functions to do much of the work, and using those will help you.
21+
- Join the pieces back together, with some extra punctuation.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Instructions
2+
3+
In this exercise you'll be processing log-lines.
4+
5+
Each log line is a string formatted as follows: `"[<LEVEL>]: <MESSAGE>"`.
6+
7+
There are three different log levels:
8+
9+
- `INFO`
10+
- `WARNING`
11+
- `ERROR`
12+
13+
You have three tasks, each of which will take a log line and ask you to do something with it.
14+
15+
## 1. Get message from a log line
16+
17+
Implement the `message` function to return a log line's message:
18+
19+
```R
20+
message("[ERROR]: Invalid operation")
21+
#> "Invalid operation"
22+
```
23+
24+
Any leading or trailing white space should be removed:
25+
26+
```R
27+
message("[WARNING]: Disk almost full\r\n")
28+
#> "Disk almost full"
29+
```
30+
31+
## 2. Get log level from a log line
32+
33+
Implement the `log_level` function to return a log line's log level, which should be returned in lowercase:
34+
35+
```R
36+
log_level("[ERROR]: Invalid operation")
37+
#> "error"
38+
```
39+
40+
## 3. Reformat a log line
41+
42+
Implement the `reformat` function that reformats the log line, putting the message first and the log level after it in parentheses:
43+
44+
```R
45+
reformat("[INFO]: Operation completed")
46+
#> "Operation completed (info)"
47+
```
48+
49+
## Note
50+
51+
Students are free to use either legacy functions from base R or the `stringr` library, and both can give short, viable solutions.

0 commit comments

Comments
 (0)