Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@
],
"status": "wip"
},
{
"slug": "log-levels",
"name": "Log Levels",
"uuid": "6c85ef11-cd2d-4718-9f75-84c467afb2f9",
"concepts": [
"strings"
],
"prerequisites": [
"vectors"
],
"status": "wip"
},
{
"slug": "mixed-juices",
"name": "Mixed Juices",
Expand Down
21 changes: 21 additions & 0 deletions exercises/concept/log-levels/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hints

## General

- Knowledge of regular expressions is not required or expected for this exercise.
- However, students who already have regex experience are free to use it if they wish.

## 1. Get message from a log line

- Think about how to split the log line into useful parts.
- You may need to remove excess whitespace.

## 2. Get log level from a log line

- There are various ways to pull out the desired substring, but position index may be the most basic.
- Remember to change case.

## 3. Reformat a log line

- You already wrote functions to do much of the work, and using those will help you.
- Join the pieces back together, with some extra punctuation.
51 changes: 51 additions & 0 deletions exercises/concept/log-levels/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Instructions

In this exercise you'll be processing log-lines.

Each log line is a string formatted as follows: `"[<LEVEL>]: <MESSAGE>"`.

There are three different log levels:

- `INFO`
- `WARNING`
- `ERROR`

You have three tasks, each of which will take a log line and ask you to do something with it.

## 1. Get message from a log line

Implement the `message` function to return a log line's message:

```R
message("[ERROR]: Invalid operation")
#> "Invalid operation"
```

Any leading or trailing white space should be removed:

```R
message("[WARNING]: Disk almost full\r\n")
#> "Disk almost full"
```

## 2. Get log level from a log line

Implement the `log_level` function to return a log line's log level, which should be returned in lowercase:

```R
log_level("[ERROR]: Invalid operation")
#> "error"
```

## 3. Reformat a log line

Implement the `reformat` function that reformats the log line, putting the message first and the log level after it in parentheses:

```R
reformat("[INFO]: Operation completed")
#> "Operation completed (info)"
```

## Note

Students are free to use either legacy functions from base R or the `stringr` library, and both can give short, viable solutions.
Loading