Giter Site home page Giter Site logo

node-debug-logging's Introduction

GCP Debug Logger Proposal

A very simple proposal of how we might add some flexible debug logging to our libraries with very little overhead (and also plug into existing popular libraries). This proposal is in Node specifically, but could be expanded to browsers and other languages.

This one file library would export a function that creates a debug logger. It takes in a namespace designation and returns a function you can call to log to that namespace. This is a very simple surface based on the built-in Node util.debugLog function, and the debug npm library.

It gives us several advantages over just using one of those:

  • Non-dogmatic: Use whatever underlying library you like for the actual output / log gathering / etc
  • Very small footprint: Requires no dependencies and is one small JS module
  • Auto plugs into whatever the user is using: just npm i debug and it'll find it and adjust; may add others later
  • Unified variables: This uses the standard namespace syntax like NODE_DEBUG or DEBUG, but it can pull values from a unified GCP_DEBUG used across many languages into those other packages' variables
  • Following on from that: GCP gets to be in control of the ultimate surface presented to users, so we can make it work across many languages and libraries (e.g. Python could also look for GCP_DEBUG in the same format)
  • Allows programmatic log sinks: Any other module or library may create a namespaced logger and call EventEmitter methods on it. These instances are shared, so you'll get the same logger as the library calling it to produce logs
๐Ÿ˜บ % node build/client.js
Random client code!
Random client code done!
๐Ÿ˜บ % NODE_DEBUG=gcp.* node build/client.js
Random client code!
GCP.PUBSUB 7536: A thing specific to gcp pubsub
GCP.PUBSUB.FOO 7536: A thing specific to gcp pubsub foo
GCP.PUBSUB.BAR 7536: A thing specific to gcp pubsub bar
Random client code done!
๐Ÿ˜บ % NODE_DEBUG=gcp.pubsub.* node build/client.js
Random client code!
GCP.PUBSUB.FOO 7542: A thing specific to gcp pubsub foo
GCP.PUBSUB.BAR 7542: A thing specific to gcp pubsub bar
Random client code done!
๐Ÿ˜บ % NODE_DEBUG=gcp.pubsub.foo node build/client.js
Random client code!
GCP.PUBSUB.FOO 7544: A thing specific to gcp pubsub foo
Random client code done!
๐Ÿ˜บ % NODE_DEBUG=gcp.pubsub,gcp.pubsub.foo node build/client.js
Random client code!
GCP.PUBSUB 7552: A thing specific to gcp pubsub
GCP.PUBSUB.FOO 7552: A thing specific to gcp pubsub foo
Random client code done!
๐Ÿ˜บ % GCP_DEBUG=gcp:pubsub,gcp:pubsub:foo node build/clientHooks.js
Random client code!
  gcp:pubsub A thing specific to gcp pubsub +0ms
  gcp:pubsub:foo A thing specific to gcp pubsub foo +0ms
oh hey i am a custom log sink and i got this: [ 'A thing specific to gcp pubsub foo' ]
Random client code done!
// Copyright 2021 Google LLC
//
// 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
//
//     https://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.

node-debug-logging's People

Contributors

feywind avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.