Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
45c57d9a
Commit
45c57d9a
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Fix log listener to not create a new object on every listen
parent
2a5aa09a
No related branches found
No related tags found
1 merge request
!6
XX-4050 / Send E2E test
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
wasm/logging.go
+35
-9
35 additions, 9 deletions
wasm/logging.go
with
35 additions
and
9 deletions
wasm/logging.go
+
35
−
9
View file @
45c57d9a
...
@@ -56,7 +56,7 @@ func LogLevel(_ js.Value, args []js.Value) interface{} {
...
@@ -56,7 +56,7 @@ func LogLevel(_ js.Value, args []js.Value) interface{} {
jww
.
SetLogThreshold
(
threshold
)
jww
.
SetLogThreshold
(
threshold
)
jww
.
SetFlags
(
log
.
LstdFlags
|
log
.
Lmicroseconds
)
jww
.
SetFlags
(
log
.
LstdFlags
|
log
.
Lmicroseconds
)
ll
:=
&
LogListener
{
threshold
,
js
.
Global
()
.
Get
(
"console"
)
}
ll
:=
New
LogListener
(
threshold
,
js
.
Global
()
.
Get
(
"console"
)
)
logListeners
=
append
(
logListeners
,
ll
.
Listen
)
logListeners
=
append
(
logListeners
,
ll
.
Listen
)
jww
.
SetLogListeners
(
logListeners
...
)
jww
.
SetLogListeners
(
logListeners
...
)
jww
.
SetStdoutThreshold
(
jww
.
LevelFatal
+
1
)
jww
.
SetStdoutThreshold
(
jww
.
LevelFatal
+
1
)
...
@@ -184,6 +184,32 @@ func (c *console) Write(p []byte) (n int, err error) {
...
@@ -184,6 +184,32 @@ func (c *console) Write(p []byte) (n int, err error) {
type
LogListener
struct
{
type
LogListener
struct
{
jww
.
Threshold
jww
.
Threshold
js
.
Value
js
.
Value
trace
*
console
debug
*
console
info
*
console
error
*
console
warn
*
console
critical
*
console
fatal
*
console
def
*
console
}
// NewLogListener initialises a new log listener that listener for the specific
// threshold and prints the logs to the Javascript console.
func
NewLogListener
(
threshold
jww
.
Threshold
,
consoleObj
js
.
Value
)
*
LogListener
{
return
&
LogListener
{
Threshold
:
threshold
,
Value
:
consoleObj
,
trace
:
&
console
{
"debug"
,
consoleObj
},
debug
:
&
console
{
"log"
,
consoleObj
},
info
:
&
console
{
"info"
,
consoleObj
},
warn
:
&
console
{
"warn"
,
consoleObj
},
error
:
&
console
{
"error"
,
consoleObj
},
critical
:
&
console
{
"error"
,
consoleObj
},
fatal
:
&
console
{
"error"
,
consoleObj
},
def
:
&
console
{
"log"
,
consoleObj
},
}
}
}
// Listen is called for every logging event. This function adheres to the
// Listen is called for every logging event. This function adheres to the
...
@@ -195,21 +221,21 @@ func (ll *LogListener) Listen(t jww.Threshold) io.Writer {
...
@@ -195,21 +221,21 @@ func (ll *LogListener) Listen(t jww.Threshold) io.Writer {
switch
t
{
switch
t
{
case
jww
.
LevelTrace
:
case
jww
.
LevelTrace
:
return
&
console
{
"debug"
,
ll
.
Value
}
return
ll
.
trace
case
jww
.
LevelDebug
:
case
jww
.
LevelDebug
:
return
&
console
{
"log"
,
ll
.
Value
}
return
ll
.
debug
case
jww
.
LevelInfo
:
case
jww
.
LevelInfo
:
return
&
console
{
"info"
,
ll
.
Value
}
return
ll
.
info
case
jww
.
LevelWarn
:
case
jww
.
LevelWarn
:
return
&
console
{
"warn"
,
ll
.
Value
}
return
ll
.
warn
case
jww
.
LevelError
:
case
jww
.
LevelError
:
return
&
console
{
"error"
,
ll
.
Value
}
return
ll
.
error
case
jww
.
LevelCritical
:
case
jww
.
LevelCritical
:
return
&
console
{
"error"
,
ll
.
Value
}
return
ll
.
critical
case
jww
.
LevelFatal
:
case
jww
.
LevelFatal
:
return
&
console
{
"error"
,
ll
.
Value
}
return
ll
.
fatal
default
:
default
:
return
&
console
{
"log"
,
ll
.
Value
}
return
ll
.
def
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment