Created
September 6, 2018 15:19
-
-
Save adilsoncarvalho/f64faaa5850cd2a19fc4cb13b4f9b2ad to your computer and use it in GitHub Desktop.
Winston -> GCP Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Logging = require('@google-cloud/logging'); | |
// Your Google Cloud Platform project ID | |
const projectId = 'wiseup-102030'; | |
// Creates a client | |
const logging = new Logging({ | |
projectId: projectId, | |
}); | |
// The name of the log to write to | |
const logName = 'winston_log'; | |
// Selects the log to write to | |
const log = logging.log(logName); | |
// The data to write to the log | |
const text = 'testes'; | |
// The metadata associated with the entry | |
const metadata = { | |
severity: 700, | |
resource: { type: 'global' }, | |
trace: 'projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824', operation: { id: 'BA6A8DDC0F31448B9627E28C372FBF0E', producer: 'teste-op' }, | |
labels: { a: "10", b: "false" }, | |
httpRequest: { | |
requestMethod: 'GET', | |
requestUrl: '/a/b/c', | |
requestSize: '1000', | |
status: 200, | |
responseSize: '10', | |
userAgent: 'teretete pá-dù-pê', | |
remoteIp: '127.0.0.1', | |
serverIp: '127.0.0.1', | |
referer: 'asdf', | |
latency: { seconds: 1, nanos: 0 }, | |
cacheLookup: false, | |
cacheHit: false, | |
cacheValidatedWithOriginServer: false, | |
cacheFillBytes: '0', | |
protocol: 'https', | |
}, | |
}; | |
// Prepares a log entry | |
const entry = log.entry(metadata, text); | |
// Writes the log entry | |
log | |
.write([ | |
entry, | |
log.entry({ labels: { a: "10", b: "false" }, trace: 'projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824', operation: { id: 'BA6A8DDC0F31448B9627E28C372FBF0E', producer: 'teste-op' }, resource: { type: 'global' }}, 'linha 1'), | |
log.entry({ labels: { a: "10", b: "false" }, trace: 'projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824', operation: { id: 'BA6A8DDC0F31448B9627E28C372FBF0E', producer: 'teste-op' }, resource: { type: 'global' }}, 'linha 2'), | |
log.entry({ labels: { a: "10", b: "false" }, trace: 'projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824', operation: { id: 'BA6A8DDC0F31448B9627E28C372FBF0E', producer: 'teste-op' }, resource: { type: 'global' }}, 'linha 3'), | |
]) | |
.then(() => { | |
console.log(`Logged: ${text}`); | |
}) | |
.catch(err => { | |
console.error('ERROR:', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment