Code Monkey home page Code Monkey logo

elm-debug-transformer's Introduction

Elm Debug Transformer

version

Transform Elm Debug.log output into nice log object with custom formatter

The standard Elm Debug.log console output:

Elm Debug.log in console without formatter

and the same output with this package

Elm Debug.log with this package and custom formatter enabled in Chrome

The main module exposes register() function that replaces your console.log() and try to parse each incoming message with Elm parser. If it fails, it would pass the original message.

Limitations

Right now you can insert only alphabet characters and spaces as a Debug.log tag.

-- this would parse successfuly
Debug.log "Some tag string" thingToPrintToConsole


-- this would NOT BE PARSED
Debug.log "Some String (with non [a-zA-Z] chars or numbers in it) " thingToPrintToConsole

This limitation is due to the problem recognizing arbitrary tag text from the rest of the types. I'm aware of that limitation and it is something that would be addressed in the upcoming versions. Thanks for understanding.

Installation

Just install this module with Yarn:

yarn add -D elm-debug-transformer

or NPM:

npm install elm-debug-transformer

Get it directly from CDN

Roman Potashow pointed out on Elm Slack that you can use the NPM package directly without the need of installing it.

<script src="https://unpkg.com/elm-debug-transformer@<VERSION>/dist/elm-console-debug.js"></script>

<script>ElmConsoleDebug.register()</script>

Usage

There is a nice summary of the usage in Alex Korban's article Get improved Debug.log output in the browser console

Register the console debugger in your main JS file before you initialize Elm application:

import * as ElmDebugger from 'elm-debug-transformer';

ElmDebugger.register();

// rest of application

Enable custom formatters in Chrome dev tools

Available in Chrome 47 and higher.

The output object is kind of chatty right now (it carries information about parsed type etc. - less verbose version is worked on right now).

If your browser have Chrome dev toools, you can enable custom formatters so you get less noice and nice output.

  • Open DevTools
  • Go to Settings ("three dots" icon in the upper right corner of DevTools > Menu > Settings F1 > Preferences > Console)
  • Check-in "Enable custom formatters"
  • Close DevTools
  • Open DevTools

Note: You might need to refresh the page first time you open Console panel with existing logs - custom formatters are applied only to newly printed console messages.

Simple object output

import * as ElmDebugger from 'elm-debug-transformer';

ElmDebugger.register({simple_mode: true});

If you are not a fan of Chromium based browser you can pass option to the register function.

register({simple_mode: true});

That way the Debug.log would output simpler JS object without type information. Tuple, Set, Array and List would become arrays and Dict would become JS object with keys and values.

Credits

This would probably not see the light of the day without Matt Zeunert and his blogpost about writing custom formatters. Thank you!

elm-debug-transformer's People

Contributors

kraklin avatar

Watchers

James Cloos 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.