Giter Club home page Giter Club logo

logger's Introduction

Welcome to logger ๐Ÿ‘‹

GitHub License GitHub commit activity GitHub Actions Workflow Status GitHub Release GitHub Release Date GitHub Issues or Pull Requests GitHub watchers GitHub forks GitHub Repo stars NPM Version NPM Type Definitions NPM Downloads Node Current

demo-code-snap

demo-output-snap


A debug.js-based logging utility:

  • Predefined log types (debug, info, warn, error);
  • Use namespace to distinguish your app logs from other outputs in browser Consoles or Terminals;
  • Enable one or more types or a log level as you need;
  • Title-scoped logs to further title your logs across app modules.

Install

npm install @gloxy/logger
# or
yarn add @gloxy/logger
# or
pnpm add @gloxy/logger

Usage

Create and logging

The only parameter namespace (e.g., 'myapp') helps distinguish these logs from other prints on Browser DevTool Consoles or Terminals.

import { createLogger } from '@gloxy/logger'
const logger = createLogger('myapp')

Logger includes 4 types of logging: debug, info, warn, and error, which use the respective console methods under the hood of the browsers and Node.js.

logger.info('Ball player %s is performing well', 'Mary')
// myapp:info Ball player Mary is performing well +0ms

Title Scoped Logger

You can create title-scoped logger logger(<title>), especially useful for module files.

/* ./logger.js  */

import { createLogger } from '@gloxy/logger'
export const logger = createLogger('myapp')
/* ./foo.js */

import { logger } from './logger'

const log = logger('foo')
log.info('Ball player %s is performing well', 'Mary')
// myapp:info [foo] Ball player Mary is performing well +0ms
/* ./bar.js */

import { logger } from './logger'

const log = logger('bar')
log.info('Ball player %s is performing well', 'Mary')
// myapp:info [bar] Ball player Mary is performing well +0ms

Enabling and Disabling

Logger is disabled by default. You can enable all log types (*) or one of them(debug, info, warn, and error) by setting name (namespace:type), or multiple types (separated with commas, namespace:type1,namespace:type2). Refer to debug.js.

Note: enable() completely overrides the previous enabled setting.

Platforms

  • To enable the logger:

    • In web browsers: localStorage.logger = 'myapp:*'
    • In Node.js: set the environment variable LOGGER=myapp:*

    Specify a type to enable the single type of logger, e.g, myapp:error.

  • Disable logger by removing these settings.

Programmatically

import { disable, enable } from '@gloxy/logger'

enable('myapp:*')
disable()

Enable by levels

Logger supports 4 levels. You can enable multiple log types by enabling a level (namespace:level).

  • 1: error
  • 2: error, warn
  • 3: error, warn, info
  • 4: error, warn, info, debug

For example, enable level 2 to output only critical error and warning logs in producation.

if (import.meta.env.NODE_ENV === 'producation') {
  enable('myapp:2')
}

Author

๐Ÿ‘ค GloryWong

Show Your Support

Give a โญ๏ธ if this project helped you!

logger's People

Contributors

glorywong avatar renovate[bot] avatar github-actions[bot] avatar

Watchers

 avatar  avatar

logger's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • googleapis/release-please-action v4
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @types/debug ^4.1.12
  • debug ^4.3.6
  • detect-node-es ^1.1.0
  • supports-color ^9.4.0
  • @antfu/eslint-config ^2.26.0
  • @commitlint/cli ^19.4.0
  • @commitlint/config-conventional ^19.2.2
  • @tsconfig/node18 ^18.2.4
  • @types/node ^20.16.1
  • eslint ^9.9.0
  • lint-staged ^15.2.9
  • perfectionist ^2.4.0
  • rimraf ^6.0.1
  • simple-git-hooks ^2.11.1
  • typescript ^5.5.4
  • vitest ^2.0.5

  • Check this box to trigger a request for Renovate to run again on this repository

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.