-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
// [START list] | ||
// [START auth] | ||
var projectId = process.env.TEST_PROJECT_ID; | ||
var keyFilename = process.env.GOOGLE_APPLICATION_CREDENTIALS; | ||
|
||
projectId = projectId || '<your-project-id>'; | ||
keyFilename = keyFilename || '/path/to/keyfile.json'; | ||
|
||
// [START require] | ||
var gcloud = require('gcloud')({ | ||
projectId: projectId, | ||
keyFilename: keyFilename | ||
}); | ||
// [END require] | ||
// [END auth] | ||
|
||
var logging = gcloud.logging(); | ||
|
||
function list(callback) { | ||
// Retrieve 3 log entries. | ||
logging.getEntries({ | ||
pageSize: 3 | ||
}, callback); | ||
} | ||
// [END list] | ||
|
||
exports.list = list; | ||
|
||
if (module === require.main) { | ||
list(function (err, result) { | ||
console.log(err, result); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "nodejs-docs-samples-logging", | ||
"description": "Node.js samples for Google Cloud Logging.", | ||
"version": "0.0.1", | ||
"private": true, | ||
"license": "Apache Version 2.0", | ||
"scripts": { | ||
"list": "node list.js", | ||
"write": "node write.js" | ||
}, | ||
"dependencies": { | ||
"gcloud": "^0.27.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* jshint camelcase:false */ | ||
'use strict'; | ||
|
||
// [START write] | ||
// [START setup] | ||
var projectId = process.env.TEST_PROJECT_ID; | ||
var keyFilename = process.env.GOOGLE_APPLICATION_CREDENTIALS; | ||
|
||
projectId = projectId || '<your-project-id>'; | ||
keyFilename = keyFilename || '/path/to/keyfile.json'; | ||
|
||
var gcloud = require('gcloud')({ | ||
projectId: projectId, | ||
keyFilename: keyFilename | ||
}); | ||
|
||
var logging = gcloud.logging(); | ||
// [END setup] | ||
|
||
function write(callback) { | ||
var log = logging.log('myLog'); | ||
|
||
// Modify this resource type to match a resource in your project | ||
// See https://cloud.google.com/logging/docs/api/ref_v2beta1/rest \ | ||
// /v2beta1/monitoredResourceDescriptors/list | ||
var resource = { | ||
type: 'gae_app', | ||
labels: { | ||
module_id: 'default', | ||
version_id: 'express' | ||
} | ||
}; | ||
|
||
var entry = log.entry(resource, { | ||
foo: 'bar' | ||
}); | ||
|
||
var secondEntry = log.entry(resource, { | ||
beep: 'boop' | ||
}); | ||
|
||
// You can log multiple entries one at a a time, but it is best to write | ||
// multiple entires together in a batch. | ||
log.write([ | ||
entry, | ||
secondEntry | ||
], callback); | ||
} | ||
// [END write] | ||
|
||
// [START deleteLog] | ||
function deleteLog(callback) { | ||
var log = logging.log('myLog'); | ||
|
||
// Delete the logs | ||
log.delete(callback); | ||
} | ||
// [END deleteLog] | ||
|
||
exports.write = write; | ||
exports.deleteLog = deleteLog; | ||
|
||
if (module === require.main) { | ||
write(function (err, apiResponse) { | ||
console.log(err, apiResponse); | ||
if (err) { | ||
return; | ||
} | ||
deleteLog(function (err, apiResponse) { | ||
console.log(err, apiResponse); | ||
}); | ||
}); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var logging = require('../../logging/list'); | ||
|
||
describe('logging/list', function () { | ||
it('should list entries', function (done) { | ||
logging.list(function (err, entries) { | ||
if (err) { | ||
return done(err); | ||
} | ||
assert.ok(Array.isArray(entries), 'should have got an array'); | ||
assert.equal(entries.length, 3, 'should have three entries'); | ||
done(); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2016, Google, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var logging = require('../../logging/write'); | ||
|
||
describe('logging/write', function () { | ||
it('should write entries', function (done) { | ||
logging.write(function (err, apiResponse) { | ||
if (err) { | ||
return done(err); | ||
} | ||
assert.deepEqual(apiResponse, {}, 'should have correct response'); | ||
done(); | ||
}); | ||
}); | ||
it('should delete entries', function (done) { | ||
logging.deleteLog(function (err, apiResponse) { | ||
if (err) { | ||
return done(err); | ||
} | ||
assert.deepEqual(apiResponse, {}, 'should have correct response'); | ||
done(); | ||
}); | ||
}); | ||
}); |