Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
dfddfae8
Commit
dfddfae8
authored
Jul 01, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PlatformLogger.printLog, .Color, .timeFormat, .color (Fix #407)
parent
04eb59dc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
15 deletions
+32
-15
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt
...rc/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt
+1
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformLogger.jvm.kt
...vmMain/kotlin/net/mamoe/mirai/utils/PlatformLogger.jvm.kt
+31
-14
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/MiraiLogger.kt
View file @
dfddfae8
...
...
@@ -262,7 +262,7 @@ open class SimpleLogger(
enum
class
LogPriority
(
@MiraiExperimentalAPI
val
nameAligned
:
String
,
@MiraiExperimentalAPI
val
simpleName
:
String
,
val
simpleName
:
String
,
@MiraiExperimentalAPI
val
correspondingFunction
:
MiraiLogger
.(
message
:
String
?,
e
:
Throwable
?)
->
Unit
)
{
VERBOSE
(
"VERBOSE"
,
"V"
,
MiraiLogger
::
verbose
),
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformLogger.jvm.kt
View file @
dfddfae8
...
...
@@ -53,50 +53,67 @@ actual open class PlatformLogger @JvmOverloads constructor(
)
:
MiraiLoggerPlatformBase
()
{
actual
constructor
(
identity
:
String
?)
:
this
(
identity
,
::
println
)
private
fun
out
(
message
:
String
?,
priority
:
String
,
color
:
Color
)
{
if
(
isColored
)
output
(
"$color$currentTimeFormatted $priority/$identity: $message"
)
else
output
(
"$currentTimeFormatted $priority/$identity: $message"
)
/**
* 输出一条日志. [message] 末尾可能不带换行符.
*/
@SinceMirai
(
"1.1.0"
)
protected
open
fun
printLog
(
message
:
String
?,
priority
:
SimpleLogger
.
LogPriority
)
{
if
(
isColored
)
output
(
"${priority.color}$currentTimeFormatted ${priority.simpleName}/$identity: $message"
)
else
output
(
"$currentTimeFormatted ${priority.simpleName}/$identity: $message"
)
}
override
fun
verbose0
(
message
:
String
?)
=
out
(
message
,
"V"
,
Color
.
RESET
)
/**
* 获取指定 [SimpleLogger.LogPriority] 的颜色
*/
@SinceMirai
(
"1.1.0"
)
protected
open
val
SimpleLogger
.
LogPriority
.
color
:
Color
get
()
=
when
(
this
)
{
SimpleLogger
.
LogPriority
.
VERBOSE
->
Color
.
RESET
SimpleLogger
.
LogPriority
.
INFO
->
Color
.
LIGHT_GREEN
SimpleLogger
.
LogPriority
.
WARNING
->
Color
.
LIGHT_RED
SimpleLogger
.
LogPriority
.
ERROR
->
Color
.
RED
SimpleLogger
.
LogPriority
.
DEBUG
->
Color
.
LIGHT_CYAN
}
override
fun
verbose0
(
message
:
String
?)
=
printLog
(
message
,
SimpleLogger
.
LogPriority
.
VERBOSE
)
override
fun
verbose0
(
message
:
String
?,
e
:
Throwable
?)
{
if
(
e
!=
null
)
verbose
((
message
?:
e
.
toString
())
+
"\n${e.stackTraceString}"
)
else
verbose
(
message
.
toString
())
}
override
fun
info0
(
message
:
String
?)
=
out
(
message
,
"I"
,
Color
.
LIGHT_GREEN
)
override
fun
info0
(
message
:
String
?)
=
printLog
(
message
,
SimpleLogger
.
LogPriority
.
INFO
)
override
fun
info0
(
message
:
String
?,
e
:
Throwable
?)
{
if
(
e
!=
null
)
info
((
message
?:
e
.
toString
())
+
"\n${e.stackTraceString}"
)
else
info
(
message
.
toString
())
}
override
fun
warning0
(
message
:
String
?)
=
out
(
message
,
"W"
,
Color
.
LIGHT_RED
)
override
fun
warning0
(
message
:
String
?)
=
printLog
(
message
,
SimpleLogger
.
LogPriority
.
WARNING
)
override
fun
warning0
(
message
:
String
?,
e
:
Throwable
?)
{
if
(
e
!=
null
)
warning
((
message
?:
e
.
toString
())
+
"\n${e.stackTraceString}"
)
else
warning
(
message
.
toString
())
}
override
fun
error0
(
message
:
String
?)
=
out
(
message
,
"E"
,
Color
.
RED
)
override
fun
error0
(
message
:
String
?)
=
printLog
(
message
,
SimpleLogger
.
LogPriority
.
ERROR
)
override
fun
error0
(
message
:
String
?,
e
:
Throwable
?)
{
if
(
e
!=
null
)
error
((
message
?:
e
.
toString
())
+
"\n${e.stackTraceString}"
)
else
error
(
message
.
toString
())
}
override
fun
debug0
(
message
:
String
?)
=
out
(
message
,
"D"
,
Color
.
LIGHT_CYAN
)
override
fun
debug0
(
message
:
String
?)
=
printLog
(
message
,
SimpleLogger
.
LogPriority
.
DEBUG
)
override
fun
debug0
(
message
:
String
?,
e
:
Throwable
?)
{
if
(
e
!=
null
)
debug
((
message
?:
e
.
toString
())
+
"\n${e.stackTraceString}"
)
else
debug
(
message
.
toString
())
}
private
val
timeFormat
=
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
SIMPLIFIED_CHINESE
)
@SinceMirai
(
"1.1.0"
)
protected
open
val
timeFormat
=
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
SIMPLIFIED_CHINESE
)
private
val
currentTimeFormatted
get
()
=
timeFormat
.
format
(
Date
())
/**
* @author NaturalHG
*/
@Suppress
(
"unused"
)
private
enum
class
Color
(
private
val
format
:
String
)
{
@MiraiExperimentalAPI
(
"This is subject to change."
)
@SinceMirai
(
"1.1.0"
)
protected
enum
class
Color
(
private
val
format
:
String
)
{
RESET
(
"\u001b[0m"
),
WHITE
(
"\u001b[30m"
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment