All,
I’ve been using the following to send log messages to my private server. Each POST
contains one log entry, sent as text/plain
.
var rayid = ""
var colo = ""
function logit(msg) {
let headers = {
'X-Log-Auth': LOG_AUTH_KEY,
'Content-Type': 'application/text'
}
let ts = new Date
let m = ts.toISOString() + ": " + colo + ": " + rayid + ": " + msg
return fetch(LOG_URL, {
method: "POST",
body: m,
headers: headers
})
}
This works great as long as the messages are a single line. Some Lua on my nginx server appends the line to a physical file in my /var/log/
and I’m a happy camper.
However, I would like to send multiple lines in one fetch()
. Basically, I want to take e.stack
, prepend my prefix to each line, and send it. I’ve found a couple of ways to prepend my prefix, so that’s not an issue. The issue is the damn newlines. No matter what I try, Buffer.from(0x0A)
and other crazy concoctions, I can’t seem to get JS to write a real newline into the String. Also, using Buffer.*
seems to blow up in Workers. :-/ . I’ve also tried [line1, line2, lin3].join('\n')
which also injects the string \x0A
instead of real newline.
Does anyone know how I can inject a real newline into the string?
EDIT: Here’s what I get:
2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: Stack:\x0A2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: Error: This is a message?\x0A2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: at failsafe (worker.js:87:13)\x0A2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: at worker.js:1371:23
And this is what I would prefer it to look like:
2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: Stack:
2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: Error: This is a message?
2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: at failsafe (worker.js:87:13)
2019-09-23T16:20:25.160Z: ORF: 51add889392fc098: OOPS: at worker.js:1371:23