~willvaughn/kata

4f4f91d9f596a11d58dc56927c2e5b1d663428ce — William Vaughn 1 year, 5 months ago 0897c59
exercism log-levels download
A exercism/clojure/log-levels/.exercism/config.json => exercism/clojure/log-levels/.exercism/config.json +20 -0
@@ 0,0 1,20 @@
{
  "authors": [
    "porkostomus"
  ],
  "files": {
    "solution": [
      "src/log_levels.clj"
    ],
    "test": [
      "test/log_levels_test.clj"
    ],
    "exemplar": [
      ".meta/exemplar.clj"
    ]
  },
  "forked_from": [
    "fsharp/log-levels"
  ],
  "blurb": "Learn about strings by parsing application logs"
}

A exercism/clojure/log-levels/.exercism/metadata.json => exercism/clojure/log-levels/.exercism/metadata.json +1 -0
@@ 0,0 1,1 @@
{"track":"clojure","exercise":"log-levels","id":"167a5ff2103241b09b107d57cd25d961","url":"https://exercism.org/tracks/clojure/exercises/log-levels","handle":"willvaughn","is_requester":true,"auto_approve":false}
\ No newline at end of file

A exercism/clojure/log-levels/HELP.md => exercism/clojure/log-levels/HELP.md +75 -0
@@ 0,0 1,75 @@
# Help

## Running the tests

## Clojure CLI

The Clojure exercises on Exercism ship with a `deps.edn` file with a `:test` alias to invoke the [cognitect-labs test-runner](https://github.com/cognitect-labs/test-runner):

``` bash
$ clj -X:test
```

## Leiningen

Leiningen can also be used to run the exercise's test by running the following command from the exercise's directory:

```bash
lein test
```

## REPL

To use the REPL to run the exercise's test, run the following command from the exercise's directory:

```bash
$ clj
```

-or-

```bash
$ lein repl
```

Then `require` the exercise's test namespace and the Clojure test namespace):

```clojure
;; replace <exercise> with the exercise's name
=> (require '<exercise>-test)
```

Then call `run-tests` on `<exercise>-test`:

```clojure
;; replace <exercise> with the exercise's name
=> (clojure.test/run-tests '<exercise>-test)
```

## Submitting your solution

You can submit your solution using the `exercism submit src/log_levels.clj` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Clojure track's documentation](https://exercism.org/docs/tracks/clojure)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

To get help if you're having trouble, you can use one of the following resources:

- [Ask Clojure](https://ask.clojure.org/) Official forum for Clojure Q & A.
- [ClojureDocs](https://clojuredocs.org) A repository of language references and examples by function or keyword.
- [/r/clojure](https://www.reddit.com/r/clojure) is the Clojure subreddit.
- [StackOverflow](http://stackoverflow.com/questions/tagged/clojure) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
- [Clojureverse](https://clojureverse.org/) Friendly and inclusive Clojure(Script) Community
\ No newline at end of file

A exercism/clojure/log-levels/HINTS.md => exercism/clojure/log-levels/HINTS.md +24 -0
@@ 0,0 1,24 @@
# Hints

## General

- The `clojure.string` namespace has many useful [string manipulation functions][string-ns].

## 1. Get message from a log line

- The [`split`][split] function can be used to split a string on a regular expression.
- The [`trim`][trim] function can be used to remove whitespace from the ends of a string.

## 2. Get log level from a log line

- A `string` can be converted to lowercase using [`lowercase`][lowercase].

## 3. Reformat a log line

- The [`str`][str] function can be used to concatenate strings.

[lowercase]: https://clojuredocs.org/clojure.string/lower-case
[split]: https://clojuredocs.org/clojure.string/split
[str]: https://clojuredocs.org/clojure.core/str
[string-ns]: https://clojuredocs.org/clojure.string
[trim]: https://clojuredocs.org/clojure.string/trim
\ No newline at end of file

A exercism/clojure/log-levels/README.md => exercism/clojure/log-levels/README.md +69 -0
@@ 0,0 1,69 @@
# Log Levels

Welcome to Log Levels on Exercism's Clojure Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)

## Introduction

A `string` in Clojure is a Java string, which is an object that represents immutable text as a sequence of Unicode characters (letters, digits, punctuation, etc.) and is defined as follows:

```clojure
(def fruit "Apple")
```

The `clojure.string` library provides many standard string manipulation and processing functions. In addition, all the usual Java methods for operating on strings are available via interop.

## 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:

```clojure
(message "[ERROR]: Invalid operation")
;;=> "Invalid operation"
```

Any leading or trailing white space should be removed:

```clojure
(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:

```clojure
(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:

```clojure
(reformat "[INFO]: Operation completed")
;;=> "Operation completed (info)"
```

## Source

### Created by

- @porkostomus
\ No newline at end of file

A exercism/clojure/log-levels/deps.edn => exercism/clojure/log-levels/deps.edn +6 -0
@@ 0,0 1,6 @@
{:aliases {:test {:extra-paths ["test"]
                  :extra-deps {io.github.cognitect-labs/test-runner
                               {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                :sha "705ad25bbf0228b1c38d0244a36001c2987d7337"}}
                  :main-opts ["-m" "cognitect.test-runner"]
                  :exec-fn cognitect.test-runner.api/test}}}
\ No newline at end of file

A exercism/clojure/log-levels/project.clj => exercism/clojure/log-levels/project.clj +4 -0
@@ 0,0 1,4 @@
(defproject log-levels "0.1.0-SNAPSHOT"
  :description "log-levels exercise."
  :url "https://github.com/exercism/clojure/tree/main/exercises/concept/log-levels"
  :dependencies [[org.clojure/clojure "1.10.0"]])
\ No newline at end of file

A exercism/clojure/log-levels/src/log_levels.clj => exercism/clojure/log-levels/src/log_levels.clj +20 -0
@@ 0,0 1,20 @@
(ns log-levels
  (:require [clojure.string :as str]))

(defn message
  "Takes a string representing a log line
   and returns its message with whitespace trimmed."
  [s]
  )

(defn log-level
  "Takes a string representing a log line
   and returns its level in lower-case."
  [s]
  )

(defn reformat
  "Takes a string representing a log line and formats it
   with the message first and the log level in parentheses."
  [s]
  )

A exercism/clojure/log-levels/test/log_levels_test.clj => exercism/clojure/log-levels/test/log_levels_test.clj +36 -0
@@ 0,0 1,36 @@
(ns log-levels-test
  (:require [clojure.test :refer [deftest testing is]]
            log-levels))

(deftest message-error-test
  (is (= "Stack overflow" (log-levels/message "[ERROR]: Stack overflow"))))

(deftest message-warning-test
  (is (= (log-levels/message "[WARNING]: Disk almost full") "Disk almost full")))

(deftest message-info-test
  (is (= (log-levels/message "[INFO]: File moved") "File moved")))

(deftest message-trim-whitespace-test
  (is (= "Timezone not set" (log-levels/message "[WARNING]:   \tTimezone not set  \r\n"))))

(deftest log-level-error-test
  (is (= "error" (log-levels/log-level "[ERROR]: Disk full"))))

(deftest log-level-warning-test
  (is (= "warning" (log-levels/log-level "[WARNING]: Unsafe password"))))

(deftest log-level-info-test
  (is (= "info" (log-levels/log-level "[INFO]: Timezone changed"))))

(deftest reformat-error-test
  (is (= "Segmentation fault (error)" (log-levels/reformat "[ERROR]: Segmentation fault"))))

(deftest reformat-warning-test
  (is (= "Decreased performance (warning)" (log-levels/reformat "[WARNING]: Decreased performance"))))

(deftest reformat-info-test
  (is (= "Disk defragmented (info)" (log-levels/reformat "[INFO]: Disk defragmented"))))

(deftest reformat-trim-whitespace-test
  (is (= "Corrupt disk (error)" (log-levels/reformat "[ERROR]: \t Corrupt disk\t \t \r\n"))))