Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
2b213d05
Commit
2b213d05
authored
Dec 19, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: properly log to the set level
parent
30bd4d34
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
src/headless/log.js
src/headless/log.js
+13
-5
No files found.
src/headless/log.js
View file @
2b213d05
import
{
get
,
isElement
}
from
'
lodash
'
;
const
LEVELS
=
{
'
debug
'
:
0
,
'
info
'
:
1
,
'
warn
'
:
2
,
'
error
'
:
3
,
'
fatal
'
:
4
}
const
logger
=
Object
.
assign
({
'
debug
'
:
get
(
console
,
'
log
'
)
?
console
.
log
.
bind
(
console
)
:
function
noop
()
{},
...
...
@@ -20,7 +27,7 @@ const log = {
* @method log#setLogLevel
* @param { integer } level - The loglevel which allows for filtering of log messages
*/
setLogLevel
(
level
)
{
setLogLevel
(
level
)
{
if
(
!
[
'
debug
'
,
'
info
'
,
'
warn
'
,
'
error
'
,
'
fatal
'
].
includes
(
level
))
{
throw
new
Error
(
`Invalid loglevel:
${
level
}
`
);
}
...
...
@@ -38,6 +45,9 @@ const log = {
* @param { integer } level - The loglevel which allows for filtering of log messages
*/
log
(
message
,
level
,
style
=
''
)
{
if
(
LEVELS
[
level
]
<
LEVELS
[
this
.
loglevel
])
{
return
;
}
if
(
level
===
'
error
'
||
level
===
'
fatal
'
)
{
style
=
style
||
'
color: maroon
'
;
}
else
if
(
level
===
'
debug
'
)
{
...
...
@@ -57,10 +67,8 @@ const log = {
}
else
if
(
level
===
'
fatal
'
)
{
logger
.
error
(
`
${
prefix
}
FATAL:
${
message
}
`
,
style
);
}
else
if
(
level
===
'
debug
'
)
{
if
(
this
.
loglevel
===
'
debug
'
)
{
logger
.
debug
(
`
${
prefix
}
${(
new
Date
()).
toISOString
()}
DEBUG:
${
message
}
`
,
style
);
}
}
else
if
(
this
.
loglevel
===
'
info
'
)
{
}
else
{
logger
.
info
(
`
${
prefix
}
${(
new
Date
()).
toISOString
()}
INFO:
${
message
}
`
,
style
);
}
},
...
...
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