Skip to content

Commit

Permalink
{ stream: process.stdout, level: 'info' },
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaTv committed Mar 29, 2023
1 parent 39e8455 commit e41b17f
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nitra/bunyan",
"version": "1.2.2",
"version": "1.3.0",
"description": "cloud run logger",
"type": "module",
"licenses": [
Expand Down
9 changes: 6 additions & 3 deletions src/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import gcpMetadata from 'gcp-metadata'

const log = bunyan.createLogger(loggerOption)

let projectId
let logE
if (traceKey) {
projectId = await gcpMetadata.project('project-id')
const projectId = await gcpMetadata.project('project-id')
logE = log.child({ [traceKey]: `projects/${projectId}/traces/${process.env.CLOUD_RUN_EXECUTION}` }, true)
} else {
logE = log
}

export default log.child({ [traceKey]: `projects/${projectId}/traces/${process.env.CLOUD_RUN_EXECUTION}` }, true)
export default logE
11 changes: 5 additions & 6 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { create, serializers } from 'bunyan-debug-stream'
import { LoggingBunyan, LOGGING_TRACE_KEY } from '@google-cloud/logging-bunyan'

export let loggerOption
export let traceKey

const name = process.env.CLOUD_RUN_JOB || process.env.K_SERVICE

if (name) {
// Imports the Google Cloud client library for Bunyan
const { LoggingBunyan, LOGGING_TRACE_KEY } = await import('@google-cloud/logging-bunyan')
traceKey = LOGGING_TRACE_KEY

// Creates a Bunyan Cloud Logging client
Expand All @@ -19,19 +20,17 @@ if (name) {
name,
streams: [
// Log to the console at 'info' and above
// { stream: process.stdout, level: 'info' },
{ stream: process.stdout, level: 'info' },
// And log to Cloud Logging, logging at 'info' and above
loggingBunyan.stream('info')
]
}
} else {
const { create, serializers } = await import('bunyan-debug-stream')

loggerOption = {
name: 'local',
streams: [
{
level: 'info',
level: 'debug',
type: 'raw',
stream: create({
forceColor: true
Expand Down
138 changes: 95 additions & 43 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@babel/parser@^7.9.4":
version "7.18.11"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.11.tgz#68bb07ab3d380affa9a3f96728df07969645d2d9"
integrity sha512-9JKn5vN+hDt0Hdqn1PiJ2guflwP+B6Ga8qbDuoF0PzzVhrzsKIJo8yGqVk6CmMHiMei9w1C1Bp9IMJSIK+HPIQ==
"@babel/parser@^7.20.15":
version "7.21.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.3.tgz#1d285d67a19162ff9daa358d4cb41d50c06220b3"
integrity sha512-lobG0d7aOfQRXh8AyklEAgZGvA4FShxo6xQbUrrT/cNBPUdIDojlokwJsQyCC/eKia7ifqM0yP+2DRZ4WKw2RQ==

"@eslint/eslintrc@^1.3.0":
version "1.3.0"
Expand Down Expand Up @@ -37,18 +37,18 @@
retry-request "^5.0.0"
teeny-request "^8.0.0"

"@google-cloud/logging-bunyan@^4.1.1":
version "4.1.1"
resolved "https://registry.yarnpkg.com/@google-cloud/logging-bunyan/-/logging-bunyan-4.1.1.tgz#8342821bf3f1c6a4a629a65ef17b2852c302a67a"
integrity sha512-ChhhXN4RjXX8TgZ5dsSw9Y5pI70+tZdwrJtuGi0OADpQ7crZsY1weDamoHB6BSOjuEksNpsBzUXWLe8bufrzzA==
"@google-cloud/logging-bunyan@^4.2.2":
version "4.2.2"
resolved "https://registry.yarnpkg.com/@google-cloud/logging-bunyan/-/logging-bunyan-4.2.2.tgz#672b840c97429822ba5208407ae6c843486610b1"
integrity sha512-YSRwP7CzK2C353zjNASG2XN8gYV3HwfoDfwk+cdcQ161BQJptzuLQcfDy9vNKaM/SMf3sL7mJIgoNbeN2YZpyA==
dependencies:
"@google-cloud/logging" "^10.1.1"
"@google-cloud/logging" "^10.2.2"
google-auth-library "^8.0.2"

"@google-cloud/logging@^10.1.1":
version "10.1.1"
resolved "https://registry.yarnpkg.com/@google-cloud/logging/-/logging-10.1.1.tgz#c3e9dff453ab85147bc5e017a836cc29e127ac19"
integrity sha512-PPtlrE+fWhJssDMcgclfzjWlRypMQxHRqPRZAFvexHcYytpAJ+ppBmczi/30LtC7fyrj9K8wvifNPI+1DSUJ4Q==
"@google-cloud/logging@^10.2.2":
version "10.4.0"
resolved "https://registry.yarnpkg.com/@google-cloud/logging/-/logging-10.4.0.tgz#3fdacfc4dfc17afb73bc2a19baf70cf2668401a9"
integrity sha512-tI2M+tTjVWRbi8KokJklpTxTqzkgZ6R4M4OuvQhTw/4tmh0HaTvKd/RYI6wQGrSw2a3j98kWBD3ryY5TcPRqog==
dependencies:
"@google-cloud/common" "^4.0.0"
"@google-cloud/paginator" "^4.0.0"
Expand All @@ -60,11 +60,11 @@
extend "^3.0.2"
gcp-metadata "^4.0.0"
google-auth-library "^8.0.2"
google-gax "^3.0.1"
google-gax "^3.5.2"
on-finished "^2.3.0"
pumpify "^2.0.1"
stream-events "^1.0.5"
uuid "^8.0.0"
uuid "^9.0.0"

"@google-cloud/paginator@^4.0.0":
version "4.0.0"
Expand All @@ -84,10 +84,10 @@
resolved "https://registry.yarnpkg.com/@google-cloud/promisify/-/promisify-3.0.0.tgz#5cd6941fc30c4acac18051706aa5af96069bd3e3"
integrity sha512-91ArYvRgXWb73YvEOBMmOcJc0bDRs5yiVHnqkwoG0f3nm7nZuipllz6e7BvFESBvjkDTBC0zMD8QxedUwNLc1A==

"@grpc/grpc-js@~1.6.0":
version "1.6.9"
resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.6.9.tgz#f8feeeb599c1ad148abaab39efbb597c22783fef"
integrity sha512-01Dy1wqXVsuiMI4m4tDoX+IPYAeNI8EsfNFPqAJBX4OiCSs5VU8Gw0pJq5NhGizH6nKUprmHb/QvxTq3d1xL5g==
"@grpc/grpc-js@~1.8.0":
version "1.8.13"
resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.8.13.tgz#e775685962909b76f8d4b813833c3d123867165b"
integrity sha512-iY3jsdfbc0ARoCLFvbvUB8optgyb0r1XLPb142u+QtgBcKJYkCIFt3Fd/881KqjLYWjsBJF57N3b8Eop9NDfUA==
dependencies:
"@grpc/proto-loader" "^0.7.0"
"@types/node" ">=12.12.47"
Expand Down Expand Up @@ -122,6 +122,13 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==

"@jsdoc/salty@^0.2.1":
version "0.2.5"
resolved "https://registry.yarnpkg.com/@jsdoc/salty/-/salty-0.2.5.tgz#1b2fa5bb8c66485b536d86eee877c263d322f692"
integrity sha512-TfRP53RqunNe2HBobVBJ0VLhK1HbfvBYeTC1ahnN64PWvyYyGebmMiPkuwvD9fpw2ZbkoPb8Q7mwy0aR8Z9rvw==
dependencies:
lodash "^4.17.21"

"@microsoft/eslint-plugin-sdl@^0.1.9":
version "0.1.9"
resolved "https://registry.yarnpkg.com/@microsoft/eslint-plugin-sdl/-/eslint-plugin-sdl-0.1.9.tgz#6f831c5a039dccc37844197c5a67c7d1ca0dc8df"
Expand Down Expand Up @@ -231,6 +238,14 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==

"@types/glob@*":
version "8.1.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.1.0.tgz#b63e70155391b0584dce44e7ea25190bbc38f2fc"
integrity sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==
dependencies:
"@types/minimatch" "^5.1.2"
"@types/node" "*"

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down Expand Up @@ -259,11 +274,29 @@
resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9"
integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==

"@types/minimatch@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==

"@types/node@*":
version "18.15.11"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f"
integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==

"@types/node@>=12.12.47", "@types/node@>=13.7.0":
version "18.7.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.4.tgz#95baa50846ae112a7376869d49fec23b2506c69d"
integrity sha512-RzRcw8c0B8LzryWOR4Wj7YOTFXvdYKwvrb6xQQyuDfnlTxwYXGCV5RZ/TEbq5L5kn+w3rliHAUyRcG1RtbmTFg==

"@types/rimraf@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-3.0.2.tgz#a63d175b331748e5220ad48c901d7bbf1f44eef8"
integrity sha512-F3OznnSLAUxFrCEu/L5PY8+ny8DtcFRjx7fZZ9bycvXRi3KPTRS9HOitGZwvPg0juRhXFWIeKX58cnX5YqLohQ==
dependencies:
"@types/glob" "*"
"@types/node" "*"

abort-controller@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
Expand Down Expand Up @@ -1218,14 +1251,15 @@ google-auth-library@^8.0.2:
jws "^4.0.0"
lru-cache "^6.0.0"

google-gax@^3.0.1:
version "3.1.4"
resolved "https://registry.yarnpkg.com/google-gax/-/google-gax-3.1.4.tgz#a277bda7461d7d3cc19340e239f7db03210f1016"
integrity sha512-+EOIVCSpFVabuqSBQHEy5kE8rGapc5sS47wbShJLzRnxIBWXs9+2vCnnmBP3pPZSsRQU08rp5C26j7spk+liUQ==
google-gax@^3.5.2:
version "3.5.8"
resolved "https://registry.yarnpkg.com/google-gax/-/google-gax-3.5.8.tgz#297b124a04c29547186c9abe5f98b10ada09a50d"
integrity sha512-bkqxv7YdYP3FGh+dywvgyctj8XM07toJ/JCWwAkmmE15QTt3ieF/f7Hpz7xG85+dGmZtQR8Y+yMo0ENFmhypNA==
dependencies:
"@grpc/grpc-js" "~1.6.0"
"@grpc/grpc-js" "~1.8.0"
"@grpc/proto-loader" "^0.7.0"
"@types/long" "^4.0.0"
"@types/rimraf" "^3.0.2"
abort-controller "^3.0.0"
duplexify "^4.0.0"
fast-text-encoding "^1.0.3"
Expand All @@ -1234,8 +1268,8 @@ google-gax@^3.0.1:
node-fetch "^2.6.1"
object-hash "^3.0.0"
proto3-json-serializer "^1.0.0"
protobufjs "7.0.0"
protobufjs-cli "1.0.0"
protobufjs "7.2.2"
protobufjs-cli "1.1.1"
retry-request "^5.0.0"

google-p12-pem@^4.0.0:
Expand Down Expand Up @@ -1500,12 +1534,13 @@ js2xmlparser@^4.0.2:
dependencies:
xmlcreate "^2.0.4"

jsdoc@^3.6.3:
version "3.6.11"
resolved "https://registry.yarnpkg.com/jsdoc/-/jsdoc-3.6.11.tgz#8bbb5747e6f579f141a5238cbad4e95e004458ce"
integrity sha512-8UCU0TYeIYD9KeLzEcAu2q8N/mx9O3phAGl32nmHlE0LpaJL71mMkP4d+QE5zWfNt50qheHtOZ0qoxVrsX5TUg==
jsdoc@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/jsdoc/-/jsdoc-4.0.2.tgz#a1273beba964cf433ddf7a70c23fd02c3c60296e"
integrity sha512-e8cIg2z62InH7azBBi3EsSEqrKx+nUtAS5bBcYTSpZFA+vhNPyhv8PTFZ0WsjOPDj04/dOLlm08EDcQJDqaGQg==
dependencies:
"@babel/parser" "^7.9.4"
"@babel/parser" "^7.20.15"
"@jsdoc/salty" "^0.2.1"
"@types/markdown-it" "^12.2.3"
bluebird "^3.7.2"
catharsis "^0.9.0"
Expand All @@ -1518,7 +1553,6 @@ jsdoc@^3.6.3:
mkdirp "^1.0.4"
requizzle "^0.2.3"
strip-json-comments "^3.1.0"
taffydb "2.6.2"
underscore "~1.13.2"

json-bigint@^1.0.0:
Expand Down Expand Up @@ -1959,23 +1993,41 @@ proto3-json-serializer@^1.0.0:
dependencies:
protobufjs "^7.0.0"

protobufjs-cli@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/protobufjs-cli/-/protobufjs-cli-1.0.0.tgz#62f99de142118f34c7b4ee53c2dc122612d2711c"
integrity sha512-7NZEBrFuuU2ZdzlhmAmvh8fdU7A4OFhzYX9AB7a5vXjopAeiks6ZgUSjOlOO7ItCDJQm3y9RWjk7spUbHc4X0w==
protobufjs-cli@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/protobufjs-cli/-/protobufjs-cli-1.1.1.tgz#f531201b1c8c7772066aa822bf9a08318b24a704"
integrity sha512-VPWMgIcRNyQwWUv8OLPyGQ/0lQY/QTQAVN5fh+XzfDwsVw1FZ2L3DM/bcBf8WPiRz2tNpaov9lPZfNcmNo6LXA==
dependencies:
chalk "^4.0.0"
escodegen "^1.13.0"
espree "^9.0.0"
estraverse "^5.1.0"
glob "^8.0.0"
jsdoc "^3.6.3"
jsdoc "^4.0.0"
minimist "^1.2.0"
semver "^7.1.2"
tmp "^0.2.1"
uglify-js "^3.7.7"

protobufjs@7.0.0, protobufjs@^7.0.0:
protobufjs@7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.2.2.tgz#2af401d8c547b9476fb37ffc65782cf302342ca3"
integrity sha512-++PrQIjrom+bFDPpfmqXfAGSQs40116JRrqqyf53dymUMvvb5d/LMRyicRoF1AUKoXVS1/IgJXlEgcpr4gTF3Q==
dependencies:
"@protobufjs/aspromise" "^1.1.2"
"@protobufjs/base64" "^1.1.2"
"@protobufjs/codegen" "^2.0.4"
"@protobufjs/eventemitter" "^1.1.0"
"@protobufjs/fetch" "^1.1.0"
"@protobufjs/float" "^1.0.2"
"@protobufjs/inquire" "^1.1.0"
"@protobufjs/path" "^1.1.2"
"@protobufjs/pool" "^1.1.0"
"@protobufjs/utf8" "^1.1.0"
"@types/node" ">=13.7.0"
long "^5.0.0"

protobufjs@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.0.0.tgz#8c678e1351fd926178fce5a4213913e8d990974f"
integrity sha512-ffNIEm+quOcYtQvHdW406v1NQmZSuqVklxsXk076BtuFnlYZfigLU+JOMrTD8TUOyqHYbRI/fSVNvgd25YeN3w==
Expand Down Expand Up @@ -2289,11 +2341,6 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

taffydb@2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/taffydb/-/taffydb-2.6.2.tgz#7cbcb64b5a141b6a2efc2c5d2c67b4e150b2a268"
integrity sha512-y3JaeRSplks6NYQuCOj3ZFMO3j60rTwbuKCvZxsAraGYH2epusatvZ0baZYA01WsGqJBq/Dl6vOrMUJqyMj8kA==

teeny-request@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/teeny-request/-/teeny-request-8.0.0.tgz#9614410ba70114fd28ba7bf5077dce3e2f02adf7"
Expand Down Expand Up @@ -2400,6 +2447,11 @@ uuid@^8.0.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

v8-compile-cache@^2.0.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
Expand Down

0 comments on commit e41b17f

Please sign in to comment.