1
1
package pprint
2
2
3
+ import java .io .PrintStream
4
+
3
5
/**
4
6
*
5
7
* @param defaultWidth How wide to allow a pretty-printed value to become
@@ -36,7 +38,38 @@ case class PPrinter(defaultWidth: Int = 100,
36
38
showFieldNames : Boolean = defaultShowFieldNames)
37
39
(implicit line : sourcecode.Line ,
38
40
fileName : sourcecode.FileName ): T = {
41
+ doLog(x, tag, width, height, indent, escapeUnicode, showFieldNames, Console .out)(line, fileName)
42
+ }
43
+
44
+ object err {
45
+ /**
46
+ * Logs a given value to stderr with some metadata to identify where the log
47
+ * message came from. Hard-coded and not very flexible, but you can easily
48
+ * implement your own log method if you want to customize it further.
49
+ */
50
+ def log [T ](x : sourcecode.Text [T ],
51
+ tag : String = " " ,
52
+ width : Int = defaultWidth,
53
+ height : Int = defaultHeight,
54
+ indent : Int = defaultIndent,
55
+ escapeUnicode : Boolean = defaultEscapeUnicode,
56
+ showFieldNames : Boolean = defaultShowFieldNames)
57
+ (implicit line : sourcecode.Line ,
58
+ fileName : sourcecode.FileName ): T = {
59
+ doLog(x, tag, width, height, indent, escapeUnicode, showFieldNames, Console .err)(line, fileName)
60
+ }
61
+ }
39
62
63
+ private def doLog [T ](x : sourcecode.Text [T ],
64
+ tag : String ,
65
+ width : Int ,
66
+ height : Int ,
67
+ indent : Int ,
68
+ escapeUnicode : Boolean ,
69
+ showFieldNames : Boolean ,
70
+ out : PrintStream )
71
+ (implicit line : sourcecode.Line ,
72
+ fileName : sourcecode.FileName ): T = {
40
73
val tagStrs =
41
74
if (tag.isEmpty) Seq ()
42
75
else Seq (fansi.Color .Cyan (tag), fansi.Str (" " ))
@@ -61,7 +94,7 @@ case class PPrinter(defaultWidth: Int = 100,
61
94
).toSeq
62
95
)
63
96
64
- println(str)
97
+ out. println(str)
65
98
x.value
66
99
}
67
100
0 commit comments