-
Notifications
You must be signed in to change notification settings - Fork 2
/
Logger.kt
85 lines (77 loc) 路 2.61 KB
/
Logger.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (c) 2018 Stanislaw stasbar Baranski
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* __ __
* _____/ /_____ ______/ /_ ____ ______
* / ___/ __/ __ `/ ___/ __ \/ __ `/ ___/
* (__ ) /_/ /_/ (__ ) /_/ / /_/ / /
* /____/\__/\__,_/____/_.___/\__,_/_/
* taxledger@stasbar.com
*/
package com.stasbar.taxledger
import com.stasbar.taxledger.translations.Text
import org.fusesource.jansi.Ansi.ansi
import org.fusesource.jansi.AnsiConsole
import java.text.SimpleDateFormat
import java.util.*
object Logger {
val dateFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
fun info(obj: Any?) {
val message = obj.toString()
val time = dateFormat.format(Date(System.currentTimeMillis()))
if (message.isNotBlank())
AnsiConsole.out.println(ansi()
.a("\n")
.fgBrightCyan()
.a(0x2714.toChar())
.a(getString(Text.Logger.INFO))
.reset()
.a(time)
.a(" ")
.a(message)
.a("\n"))
}
fun err(obj: Any?) {
val message = obj.toString()
val time = dateFormat.format(Date(System.currentTimeMillis()))
if (message.isNotBlank())
AnsiConsole.out.println(ansi()
.a("\n")
.fgBrightRed()
.a(0x2716.toChar())
.a(getString(Text.Logger.ERROR))
.reset()
.a(time)
.a(" ")
.a(message)
.a("\n"))
}
fun d(obj: Any?) {
if (!DEBUG) return
val message = obj.toString()
val time = dateFormat.format(Date(System.currentTimeMillis()))
AnsiConsole.out.println(ansi()
.a("\n")
.fgBrightGreen()
.a(0x2716.toChar())
.a(getString(Text.Logger.DEBUG))
.reset()
.a(time)
.a(" ")
.a(message)
.a("\n"))
}
}