Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add winston logging transport #1830

Merged
merged 15 commits into from
Feb 8, 2017

Conversation

ofrobots
Copy link
Contributor

@ofrobots ofrobots commented Nov 28, 2016

This PR adds a new module @google-cloud/logging-winston that provides simple, minimal config way of logging to Stackdriver Logging from applications using winston.

The code is fairly small, but it should be a standalone module because we need to depend upon winston (the transport must be an instance of winston.Transport). Adding this dependency to @google-cloud/logging doesn't make sense (we should not install winston for people who are not asking for winston support).

/cc @cristiancavalli

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Nov 28, 2016
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Dec 2, 2016
var metadata = this.metadata_;
if (meta) {
// Logging proto requires that the label values be strings, so we convert
// using util.inspect.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Dec 2, 2016
@stephenplusplus
Copy link
Contributor

@ofrobots I've added a commit. The main differences are,

  • code style (in docs & JSDocs)
  • examples (using new to instantiate winston & the transport -> winston.add)

Can you take a quick look and make sure it still behaves as intended?

Copy link
Contributor Author

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Added comments.

});

This comment was marked as spam.


### Elsewhere

If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account:

This comment was marked as spam.

*/
function LoggingWinston(options) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* either succeeds or gives up writing the log entry to the remote server.
* @param {object=} metadata - Winston-provided metadata that should be attached
* to the log entry. Each property will be converted to a string using
* `JSON.stringify`.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

if (_.isFunction(meta) && !callback) {
callback = meta;
meta = null;
LoggingWinston.prototype.log = function(levelName, msg, metadata, callback) {

This comment was marked as spam.

This comment was marked as spam.


var metadata = this.metadata_;
if (meta) {
if (metadata) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus stephenplusplus added the api: logging Issues related to the Cloud Logging API. label Dec 5, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 99.792% when pulling 568fec4 on ofrobots:logging-winston into ac87e18 on GoogleCloudPlatform:master.


If you are running your application in a different environment, for example, locally, on-premise, or on another cloud provider, you may need to provide some configuration.
If you are running this client on Google Compute Engine, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

stephenplusplus commented Dec 12, 2016

I'll finish up the unit tests for this. Are we including this in the google-cloud bundle, e.g.:

var gcloud = require('google-cloud')();
var transport = gcloud.loggingWinston;

Also, is there a better name than logging-winston? Generally, var names coincide with the module name, so this isn't ideal:

var stackdriverTransport = require('@google-cloud/logging-winston')

@ofrobots
Copy link
Contributor Author

/cc @JustinBeckwith @omaray for more opinions on the name.

This library isn't a client library but rather an integration library. I think the general rule of var names coinciding doesn't have to apply here. Module names are primarily for discoverability of purpose, so I still prefer @google-cloud/logging-winston. The fact that this returns a winston transport would make complete sense to winston users.

Perhaps we should change the examples to the following to make things more elegant:

var transport = require('@google-cloud/logging-winston');

I don't have very strong opinions on bundling this with google-cloud as I am not too familiar with the precedents in this library. My personal preference would be to not include integration libraries in the default bundle. The users who need to use it can add it explicitly.

@ofrobots
Copy link
Contributor Author

I've improved the examples.

@ofrobots ofrobots force-pushed the logging-winston branch 3 times, most recently from a8bdbb4 to a3ee52a Compare January 3, 2017 22:19
@ofrobots
Copy link
Contributor Author

ofrobots commented Jan 4, 2017

@stephenplusplus I've add some more unit tests. PTAL.

@stephenplusplus
Copy link
Contributor

I made some alterations from your last commit with regards to the input validation and testing strategy, keeping it more in line with the conventions here-- letting validation happen "last-minute", by an upstream module or API request, meaning we try to only throw if the next line of code in our script wouldn't work if they gave us something invalid. And with the tests, we stub everything to make sure the tests are as isolated as possible from logic that exists anywhere else.

PTAL!

@ofrobots
Copy link
Contributor Author

ofrobots commented Feb 3, 2017

Sorry for the delay. LGTM.

@ofrobots
Copy link
Contributor Author

ofrobots commented Feb 7, 2017

When should we expect this to land?

@stephenplusplus stephenplusplus merged commit 4a9bd94 into googleapis:master Feb 8, 2017
@ofrobots ofrobots deleted the logging-winston branch February 9, 2017 14:52
@ofrobots
Copy link
Contributor Author

ofrobots commented Feb 9, 2017

Thanks for landing. Can we publish a package for this too?

@stephenplusplus
Copy link
Contributor

Published as 0.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants