Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smart_hotel_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宏
smart_hotel_app
Commits
2eaabcd0
Commit
2eaabcd0
authored
Jun 11, 2026
by
张宏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
2fd41bd6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
1 deletion
+64
-1
logger.dart
lib/utils/logger.dart
+64
-1
No files found.
lib/utils/logger.dart
View file @
2eaabcd0
import
'dart:convert'
;
import
'package:logger/logger.dart'
as
pkg
;
import
'package:logger/logger.dart'
as
pkg
;
class
_LongMessagePrinter
extends
pkg
.
LogPrinter
{
final
pkg
.
PrettyPrinter
_prettyPrinter
;
final
int
_chunkSize
;
_LongMessagePrinter
({
required
int
methodCount
,
required
int
errorMethodCount
,
required
int
lineLength
,
required
bool
colors
,
required
bool
printEmojis
,
int
chunkSize
=
800
,
})
:
_prettyPrinter
=
pkg
.
PrettyPrinter
(
methodCount:
methodCount
,
errorMethodCount:
errorMethodCount
,
lineLength:
lineLength
,
colors:
colors
,
printEmojis:
printEmojis
,
),
_chunkSize
=
chunkSize
;
String
_tryPrettyJson
(
String
message
)
{
try
{
final
trimmed
=
message
.
trim
();
if
((
trimmed
.
startsWith
(
'{'
)
&&
trimmed
.
endsWith
(
'}'
))
||
(
trimmed
.
startsWith
(
'['
)
&&
trimmed
.
endsWith
(
']'
)))
{
final
decoded
=
jsonDecode
(
trimmed
);
return
const
JsonEncoder
.
withIndent
(
' '
).
convert
(
decoded
);
}
}
catch
(
_
)
{}
return
message
;
}
List
<
String
>
_chunk
(
String
text
)
{
if
(
text
.
length
<=
_chunkSize
)
return
[
text
];
final
chunks
=
<
String
>[];
for
(
var
i
=
0
;
i
<
text
.
length
;
i
+=
_chunkSize
)
{
chunks
.
add
(
text
.
substring
(
i
,
i
+
_chunkSize
>
text
.
length
?
text
.
length
:
i
+
_chunkSize
));
}
return
chunks
;
}
@override
List
<
String
>
log
(
pkg
.
LogEvent
event
)
{
final
original
=
event
.
message
;
final
output
=
StringBuffer
();
final
lines
=
const
LineSplitter
().
convert
(
_tryPrettyJson
(
original
.
toString
()));
for
(
final
line
in
lines
)
{
for
(
final
chunk
in
_chunk
(
line
))
{
output
.
writeln
(
chunk
);
}
}
final
wrappedEvent
=
pkg
.
LogEvent
(
event
.
level
,
output
.
toString
().
trimRight
(),
error:
event
.
error
,
stackTrace:
event
.
stackTrace
,
);
return
_prettyPrinter
.
log
(
wrappedEvent
);
}
}
class
Log
{
class
Log
{
static
final
pkg
.
Logger
_logger
=
pkg
.
Logger
(
static
final
pkg
.
Logger
_logger
=
pkg
.
Logger
(
printer:
pkg
.
Pretty
Printer
(
printer:
_LongMessage
Printer
(
methodCount:
0
,
methodCount:
0
,
errorMethodCount:
5
,
errorMethodCount:
5
,
lineLength:
90
,
lineLength:
90
,
colors:
true
,
colors:
true
,
printEmojis:
true
,
printEmojis:
true
,
chunkSize:
800
,
),
),
);
);
...
...
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