-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddLog.kt
45 lines (40 loc) · 1.7 KB
/
AddLog.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package spp.demo.command
import org.slf4j.LoggerFactory
import java.util.concurrent.ThreadLocalRandom
/**
* This class is used to demonstrate the `Add Log` command.
*
* **Usage:**
* Open the Source++ Command Palette with `Ctrl+Shift+S` and search for `Add Log`.
*
* **Command source code:**
* [Add Log](https://github.com/sourceplusplus/jetbrains-commander/blob/master/resources/.spp/plugins/add-log/plugin.kts)
*/
class AddLog {
companion object {
private val log = LoggerFactory.getLogger(AddLog::class.java)
}
/**
* Execute the **Add Log** command with your cursor on line 34 to set up a live log
* **before** the execution of that line. This will open the log configuration inlay. This inlay
* allows you to input a new log message to output. You can use the "$" symbol to reference
* variables in the current scope. You can also use the "Ctrl+Space" shortcut to see a list of
* available variables. Try outputting the following message:<br></br>
* **Random number: $randomNumber - Even: $isEven**
*/
fun simpleLog() {
val randomNumber = ThreadLocalRandom.current().nextInt()
val isEven = randomNumber % 2 == 0
}
/**
* The **Add Log** command can also be used with the **Tail Logs** command. Execute the
* **Tail Logs** command with your cursor between or on lines 42-44. Then execute the
* **Add Log** command with your cursor on line 45. Try outputting the following message:<br></br>
* **And is even: $isEven**
*/
fun simpleLogWithTailLogs() {
val randomNumber = ThreadLocalRandom.current().nextInt()
val isEven = randomNumber % 2 == 0
log.info("Random number: {}", randomNumber)
}
}