All Projects → JohnReedLOL → Scala Trace Debug

JohnReedLOL / Scala Trace Debug

Licence: mit
Macro based print debugging. Locates log statements in your IDE.

Programming Languages

java
68154 projects - #9 most used programming language
scala
5932 projects
macros
77 projects

Projects that are alternatives of or similar to Scala Trace Debug

React Native Logs
Performance-aware simple logger for React-Native with namespaces, custom levels and custom transports (colored console, file writing, etc.)
Stars: ✭ 84 (-23.64%)
Mutual labels:  debugging, debug
Unitydbgdraw
DbgDraw is an API that provides the ability to render various 2D and 3D shapes for visual debugging purposes.
Stars: ✭ 20 (-81.82%)
Mutual labels:  debugging, debug
Node In Debugging
《Node.js 调试指南》
Stars: ✭ 6,139 (+5480.91%)
Mutual labels:  debugging, debug
Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+3326.36%)
Mutual labels:  debugging, debug
Android Debug Database
A library for debugging android databases and shared preferences - Make Debugging Great Again
Stars: ✭ 7,946 (+7123.64%)
Mutual labels:  debugging, debug
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+3272.73%)
Mutual labels:  debugging, debug
Bugsnag Laravel
Bugsnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
Stars: ✭ 746 (+578.18%)
Mutual labels:  debugging, debug
caddy-trace
Request Debugging Middleware Plugin for Caddy v2
Stars: ✭ 25 (-77.27%)
Mutual labels:  debugging, debug
Debug
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
Stars: ✭ 9,912 (+8910.91%)
Mutual labels:  debugging, debug
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-62.73%)
Mutual labels:  debug, stack-traces
Tensorwatch
Debugging, monitoring and visualization for Python Machine Learning and Data Science
Stars: ✭ 3,191 (+2800.91%)
Mutual labels:  debugging, debug
Debugdrawer
Android Debug Drawer for faster development
Stars: ✭ 1,168 (+961.82%)
Mutual labels:  debugging, debug
Bistoury
Bistoury是去哪儿网的java应用生产问题诊断工具,提供了一站式的问题诊断方案
Stars: ✭ 3,198 (+2807.27%)
Mutual labels:  debugging, debug
Boxx
Tool-box for efficient build and debug in Python. Especially for Scientific Computing and Computer Vision.
Stars: ✭ 429 (+290%)
Mutual labels:  debugging, debug
Debugo
一个可能有点用的 iOS 调试工具~
Stars: ✭ 258 (+134.55%)
Mutual labels:  debugging, debug
Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
Stars: ✭ 727 (+560.91%)
Mutual labels:  debugging, stack-traces
CrashLogger
A dll injected into process to dump stack when crashing.
Stars: ✭ 19 (-82.73%)
Mutual labels:  debugging, debug
pydbg
Python implementation of the Rust `dbg` macro
Stars: ✭ 85 (-22.73%)
Mutual labels:  debugging, debug
Bugsnag Android
Bugsnag crash monitoring and reporting tool for Android apps
Stars: ✭ 990 (+800%)
Mutual labels:  debugging, debug
Bugsnag Node
[DEPRECATED] Please upgrade to our Universal JS notifier "@bugsnag/js" • https://github.com/bugsnag/bugsnag-js
Stars: ✭ 48 (-56.36%)
Mutual labels:  debugging, debug

scala-trace-debug: print debugging on steroids

**This library is deprecated. If you are using Scala 2.11 or above, please use https://github.com/JohnReedLOL/pos **


scala-trace-debug is a hyperlink based print debugging system designed to work with any IDE or text editor that supports stack trace highlighting. It had its origins in a print debugging system developed in Java for undergrads, and evolved into something production ready. Using compile-time macros in Scala and run-time switches in Java, scala-trace-debug makes your print statements and assertions easier than ever to locate. Use it to append a "smart" hyperlink to your sourcecode, avoiding the need to "grep", and turn it off by recompiling with the ENABLE_TRACE_DEBUG environment variable set to false. Write smart print statements and assertions that print out your source code. Never use System.out/err.println again.

Build Status Maven Central


Table of Contents


Locate Statements:

Append Position

^ Clicking on "Main.scala:12" will cause you to jump to Main.scala, line 12.

Use it with a logger:

Locate

"Pos() does not rely on runtime reflection or stack inspection, and is done at compile-time using macros. This means that it is both orders of magnitude faster than e.g. getting file-name and line-numbers using stack inspection, and also works on Scala.js where reflection and stack inspection can't be used." - taken from Li Haoyi's sourcecode


Getting Started:

scala-trace-debug is availiable through maven central as well as bintray.

Add this to your pom.xml:

<dependency>
  <groupId>com.github.johnreedlol</groupId>
  <artifactId>scala-trace-debug_2.11</artifactId>
  <version>4.5.0</version>
  <type>pom</type>
</dependency>

Add this to your build.sbt:

libraryDependencies += "com.github.johnreedlol" %% "scala-trace-debug" % "4.5.0"

If you get: "NoClassDefFoundError: scala/reflect/runtime/package ... Caused by: java.lang.ClassNotFoundException"

Add: libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value

Java users need to add this dependency to the maven build.

For Scala 2.12.0 and above, please build this branch.


Instructions (for IntelliJ IDE):

  1. Add the appropirate dependency from Getting Started

  2. import com.github.johnreedlol._

  3. Make sure that you have IntelliJ run configuration set up to run from the IntelliJ console

Run > Edit Configurations... > SBT Task

Click the green "+" (Add new configuration)

Example

  • Place some calls to scala trace debug and click the green 'Debug' (Shift+F9) button and follow the stack traces in the console.

  • Use the IntelliJ console arrows to navigate up and down the stack traces.

IntelliJ console

For smooth scrolling, use the keyboard shortcut Ctr+Alt+Down


Scala Examples:

Scala Example

^ Note that the Debug object does not use compile time macros and is a throwback to the days when this project was a print debugging system for Java.

Code Example:
def sleep() = Thread.sleep(60) // to prevent output mangling

import com.github.johnreedlol.Pos
Pos.err("Standard error") ; sleep()
Pos.out("Hello World")
println("an error message" + Pos()) /*position*/ ; sleep()
Debug Statements (Java Compatible):
import com.github.johnreedlol.Debug

// debug traces are clickable

Debug.err("trace to standard error")
Debug.err("trace to standard error", numLines = 2)
Debug.arrayErr(Array(1,2,3))
Debug.arrayErr(Array(1,2,3), numElements = 2,  numLines = 2) ; sleep()

Debug.out("trace to standard out")
Debug.out("trace to standard out", numLines = 2)
Debug.arrayOut(Array(1,2,3))
Debug.arrayOut(Array(1,2,3), start = 1, numLines = 2) ; sleep()
Assertions (Java Compatible):
// assertions are totally fatal (full stop)
Debug.assert(1 == 1, "one must equal one")
Debug.assertOut(1 == 1, "one must equal one") ; sleep()

// turn them off like this
Debug.fatalAssertOff()
Debug.assert(1 == 2, "one must equal two")   // nothing happens

// checks are non-fatal (no thread death)
Debug.check("one" == 2, "one must equal one") ; sleep()
// output is colored bright red for visibility
Debug.checkOut("one" == 2, "one must equal one", numLines = 1) ; sleep()
Macros:

Example macro

^ In this case the macro on line 62 is desugaring the code to standard out.

import com.github.johnreedlol.Macro

// Macro methods use advanced Scala features to print code and types

Macro.contentsOut(List(1, 2, 3))
Macro.contentsOut(List(1, 2, 3), numLines = 2) ; sleep()

Macro.contentsErr(List(1, 2, 3))
Macro.contentsErr(List(1, 2, 3), numLines = 2) ; sleep()

Macro.checkCode("one" == 2)
Macro.assertCode("one" == "one") ; sleep()

val (one, two, three) = (1, 2, 3)

// desugar statements will desugar your code, turning whitespace into parenthesis and inserting implicits

Macro.desugarOut(one + two / three)
Macro.codeOut(one + two / three) ; sleep()

// codeOut and codeErr will print variable names

Macro.desugarErr(one + two / three)
Macro.codeErr(one + two / three) ; sleep()
Implicit Conversions:
import com.github.johnreedlol.implicitlyTraceable

// you can easily remove calls to ".out" and ".err" from the source by pressing Ctr-R (find-replace)

"foo bar baz".out
"foo bar baz".err ; sleep()

println("")

import com.github.johnreedlol.implicitlyAssertable

"foo bar".assertEq("foo bar", "foo bar must equal foo bar")
2.check(_ + 3 == 5, "two plus three is five")
^ Run it yourself with "sbt test:run" ^

Java Examples:

Java Screenshot

^ Note that all my stack traces are off by one. This only happens when the methods are called from Java. To get around this, specify "2" for last parameter (2 lines of stack trace). ^

Note the jar file name in the stack trace.

Copy-paste Java example here.


Master Shutoff Switch (Java Capable):

If you set the environment variable ENABLE_TRACE_DEBUG to false, runtime printing and assertions will be disabled. Compile time macros like Pos will require a clean (sbt clean) followed by a recompile for this change to take effect.

Instead of an environment variable, a system property may also be used. "The system property takes precedence over the environment variable".

Runtime Switches (Java Capable):

Debug.traceErrOn/Off()
Debug.traceOutOn/Off()
Debug.fatalAssertOn/Off()
Debug.nonFatalAssertOn/Off() // assertNonFatal = check
Debug.setElementsPerRow() // For container printing

Code layout:

Currently all the actual printing is done in Printer.scala, all the implicit conversions are in package.scala, and all the calls to the "Debug" object are in Debug.scala


Developer's Guide

  1. git clone https://github.com/JohnReedLOL/scala-trace-debug 3.0
  2. cd ./4.0/
  3. sbt test
  4. sbt test:run [pick option 1 - it should fail with exit code 7 for fatal assertion]
  5. sbt test:run [pick option 2]
  6. sbt package

Advanced:

$ sbt
[info] Loading project definition from /home/.../scala-trace-debug/project
[info] Set current project to scala-trace-debug (in build file:/home/.../scala-trace-debug/)
> + clean
> + compile 
> + test
> + package
  • "+" means "cross-building"

Artifacts are published using > publish-signed, the public key is 3E2B27D9


Building:

I personally build scala-trace-debug with Java 7 (javac 1.7.0_79) and sbt version 0.13.7. It builds with Scala 2.11.7 but also cross-builds for 2.10.4 and 2.11.2.


Contributors


Links (Old):

See ScalaDoc in source code for in detail documentation.

See also: http://stackoverflow.com/questions/36194905/how-can-we-trace-expressions-print-statements-with-line-numbers-in-scala/36194986#36194986

http://stackoverflow.com/questions/4272797/debugging-functional-code-in-scala/36287172#36287172

Old version of this library: https://www.reddit.com/r/scala/comments/4aeqvh/debug_trace_library_needs_users_review/

Less old version of this library: https://www.reddit.com/r/scala/comments/4fap0r/making_debugging_easier/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].