Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
repos
security
Test - Service Runner Fork - NodeJS
Commits
421d2f1b
Commit
421d2f1b
authored
Apr 08, 2020
by
Ppchelko
Committed by
Petr Pchelko
Apr 08, 2020
Browse files
Make the NamedLevel logger a raw objectmode stream
parent
d3fc15b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
421d2f1b
...
...
@@ -147,6 +147,8 @@ logging:
sampled_levels
:
'
trace/webrequest'
:
0.2
streams
:
-
type
:
stdout
# log to stdout
named_levels
:
true
# emit log level name instead of index. e.g. INFO vs 30
# Use gelf-stream -> logstash
-
type
:
gelf
host
:
logstash1003.eqiad.wmnet
...
...
lib/logger.js
View file @
421d2f1b
'
use strict
'
;
const
Writable
=
require
(
'
stream
'
).
Writable
;
const
bunyan
=
require
(
'
bunyan
'
);
const
gelfStream
=
require
(
'
gelf-stream
'
);
const
syslogStream
=
require
(
'
bunyan-syslog-udp
'
);
...
...
@@ -12,15 +13,23 @@ function extractSimpleLevel(levelPath) {
return
typeof
levelPath
===
'
string
'
&&
levelPath
.
split
(
'
/
'
)[
0
];
}
function
NamedLevelStdout
()
{
return
{
write
:
(
entry
)
=>
{
// Kind of inefficient approach
var
logObject
=
JSON
.
parse
(
entry
);
logObject
.
level
=
bunyan
.
nameFromLevel
[
logObject
.
level
].
toUpperCase
();
process
.
stdout
.
write
(
JSON
.
stringify
(
logObject
)
+
'
\n
'
);
}
};
class
NamedLevelStdout
extends
Writable
{
constructor
(
downstream
,
options
=
{})
{
super
(
Object
.
assign
(
options
,
{
objectMode
:
true
}));
this
.
downstream
=
downstream
;
}
_write
(
logEntry
,
encoding
,
callback
)
{
logEntry
.
level
=
bunyan
.
nameFromLevel
[
logEntry
.
level
].
toUpperCase
();
this
.
downstream
.
write
(
JSON
.
stringify
(
logEntry
)
+
'
\n
'
,
encoding
,
callback
);
}
destroy
()
{
super
.
destroy
();
this
.
downstream
.
destroy
();
}
}
const
streamConverter
=
{
...
...
@@ -52,16 +61,18 @@ const streamConverter = {
};
},
stdout
(
stream
,
conf
)
{
return
{
stream
:
process
.
stdout
,
level
:
stream
.
level
||
conf
.
level
};
},
namedstdout
(
stream
,
conf
)
{
return
{
stream
:
NamedLevelStdout
(),
level
:
stream
.
level
||
conf
.
level
};
if
(
stream
.
named_levels
)
{
return
{
type
:
'
raw
'
,
stream
:
new
NamedLevelStdout
(
process
.
stdout
),
level
:
stream
.
level
||
conf
.
level
};
}
else
{
return
{
stream
:
process
.
stdout
,
level
:
stream
.
level
||
conf
.
level
};
}
},
debug
(
stream
,
conf
)
{
try
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment