Giter Club home page Giter Club logo

huon's Introduction

Huon Build Status

A console.log wrapper for ClojureScript.

Goals

  • Lazy message evaluation
  • Simple API

Non-goals

  • Highly configurable

Installation

Add [org.harto/huon "1.0.0-SNAPSHOT"] as a dependency in project.clj (or similar).

Basic usage

(ns foo.bar
  (:require [huon.log :as log]))

;; optional; defaults to :warn
(log/configure! {:root-level :info})

(log/debug "an invisible message")
(log/info "hello" "world")

Output:

[foo.bar:8] hello world

Available logging macros are debug, info, warn and error.

time macro

The time macro wraps console.time / console.timeEnd for basic profiling:

(log/time "reticulating splines"
  (reticulate-splines))

Output:

[foo.bar:27] reticulating splines: 37.192ms

Additional API functions

  • (configure! opts) - set logging configuration according to options
  • (set-root-level! level) - reset the root logger level (e.g. (set-root-level! :error))
  • (set-level! logger-name level) - reset a logger level (e.g. (set-level! "foo.bar" :warn))

Configuration options

  • :show-level? - whether to print the log level alongside each message (default: false)
  • :format - a function to customize formatting of each message argument (default: str)
  • :root-level - the global logging threshold (default: :warn)
  • :logger-levels - a mapping of namespace names to log levels (e.g. {"foo" :info, "foo.bar" :debug})

Development

The automated test suite is runnable via bin/run-tests.

License

MIT; see LICENSE.

huon's People

Contributors

eval avatar harto avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

eval

huon's Issues

logging not appearing on Node.js for optimizations other than none

Code demonstrating this: https://github.com/eval/huon/tree/logging-disabled-for-simple#logging-issue-when-targetting-nodejs

tl;dr:

  • logging is shown for optimization none (-t node)
  • logging is not shown for other optimizations (-t node)
  • there appears no difference when not targetting node

origin

I found that goog.debug.Console.console_ is null for optimization != none whereas it equals js/console for optimization == none.
relevant line: https://github.com/google/closure-library/blob/master/closure/goog/debug/console.js#L156

speculation it appears to be an load ordering issue with ClojureScript.

possible workaround

As part of enabling logging, we should setConsole to js/console (see code in issue).

seeing log-level of a message

Currently you cannot see what the log-level of an individual message is.
Would you be interested in a PR that prepends messages with the log-level?

Example:
current:

[1.880s] [foo.ns1] just some info
[2.880s] [foo.ns2] something going wrong here

wanted:

[1.880s] [foo.ns1] INFO just some info
[2.880s] [foo.ns2] ERROR something going wrong here

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.