Skip to content

Commit

Permalink
feat: sync support (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Aug 15, 2022
1 parent 31fe326 commit 85ec4d6
Show file tree
Hide file tree
Showing 2 changed files with 903 additions and 17 deletions.
21 changes: 16 additions & 5 deletions lib/cloud-logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ class CloudLogging {
this._resource = Object.assign({ type: 'global' }, options.resourceSettings)
this._defaultLabels = Object.assign(
{},
{ logger: 'pino' },
{ logger: 'pino', agent: 'cloud_pine' },
options.defaultLabels
)
this._log = null
// Indicates whether the logs will be forward to stdout or
// through networking to GCP
this._sync = options.sync ?? false
this._logOptions = options.logOptions
}

Expand All @@ -24,14 +27,18 @@ class CloudLogging {
return this._resource
}

get sync () {
return this._sync
}

async init () {
await this.logging.setProjectId()
await this.logging.setDetectedResource()

const labels = Object.assign(
{},
this._resource.labels,
this.logging.detectedResource.labels
this.logging.detectedResource?.labels
)

this._resource = Object.assign(
Expand All @@ -41,7 +48,10 @@ class CloudLogging {

this._resource.labels = labels

this._log = this.logging.log(this.name)
this._log = this._sync
? this.logging.logSync(this.name)
: this.logging.log(this.name)

return this._log
}

Expand Down Expand Up @@ -72,6 +82,8 @@ class CloudLogging {
log.meta // Custom property to add more meta to the LogEntry
)

delete log.meta

meta.resource = Object.assign({}, this._resource, meta.resource)
meta.labels = Object.assign({}, this._defaultLabels, meta.labels)

Expand All @@ -83,8 +95,7 @@ class CloudLogging {
log.message = log.message ?? log.msg
delete log.msg

const entry = this._log.entry(meta, log)
this._log.write(entry)
this._log.write(this._log.entry(meta, log))
}
}

Expand Down
Loading

0 comments on commit 85ec4d6

Please sign in to comment.