Skip to content

Console logging for enhancing logs with source filenames and line numbers while removing all logs in production.

License

Notifications You must be signed in to change notification settings

GlitchyByte/dlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dlog

version

Dev console logger library (with Babel plugin, Vite compatible)

Console logging library and Babel/Vite plugin that enhances logs by automatically injecting source filenames (relative to project root) and line numbers into log statements. Removes all logging in production environments.

Goals

  • Print original (not transpiled) source filename and line number.
  • Usable in React and React Native development.
  • Completely remove logging in production.

API

dlog.log("message")   // Prints to console.log
dlog.error("message") // Prints to console.error

How to use

Add package to your project

npm install --save-dev @glitchybyte/dlog

In Babel (e.g., Expo and React Native development)

Add plugin to babel.config.js

{
  presets: [...],
  plugins: [
    ...,
    "@glitchybyte/dlog/babel"
  ]
}

In Vite (e.g., React development)

Add plugin to vite.config.ts

import dlog from "@glitchybyte/dlog/babel"

export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [dlog]
      }
    })
  ]
})

Use it in your code

// path/to/my-code.ts
import { dlog } from "@glitchybyte/dlog"

dlog.log("Some message!")
// @path/to/my-code.ts:4 Some message!

About

Console logging for enhancing logs with source filenames and line numbers while removing all logs in production.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •