Last question of the day… I am wondering if there...
# box-products
r
Last question of the day… I am wondering if there is a commandbox-y way of using
print
from inside models/services. Currently, if I want to print to the console from a service, I am passing in an instance of
print
as an argument to my service method.
b
*
What I prefer however, is to use the interactive job UI from services.
Copy code
job.start( 'This is my job to run' );
  job.addLog( 'Still going...' );
  job.addLog( 'Now we''re getting somewhere.' );
  job.addLog( 'Almost done!' );;
job.complete();
👍 1
It sort of depends on what you're after I suppose. For example, if you want your output to be part of a command whose output can be piped into another command, you don't want to use the
printbuffer.line().toConsole()
method as it will flush immediatley
Or, if possible, have the model only return data and then control the output in the command.
r
I am in the process of rewriting a module and was using it mainly for debugging
b
Printing to the console is your model is SORT OF like output HTML from your model in MVC. But sometimes you actually want something that's updating the console in the middle of execution so it can make sense
r
Sounds like injecting the printBuffer would probably work for me. Passing
print
as an argument works, just didnt feel right
b
For fast and dirty debugging, just do
Copy code
systemOutput( myVar, true )
r
Heck, that is even better
b
The nice thing about the print buffer is you can throw anything at it and you get nicve, colored formatted dumps
👍 1
r
I tried writeOutput() but that didn’t work
b
yeah, writeoutput writes to the HTTP request's response buffer which ... doesn't exist here 🙂
systemOutput writes to Java's
System.out
r
Silly question, but do you know the wirebox injection the print buffer?
b
You can also do
Copy code
dump( var=myVar, output="console" )
but • the formatting is crap • it's annoying to type
😂 1
Silly question, but do you know the wirebox injection for the print buffer?
Because that's the name of the CFC in the
system/util
directory https://s3.amazonaws.com/apidocs.ortussolutions.com/commandbox-core/5.7.0/index.html?commandbox/system/util/package-summary.html and all of those CFCs are directly mapped in WireBox in the CommandBox core https://github.com/Ortus-Solutions/commandbox/blob/development/src/cfml/system/config/WireBox.cfc#L94
So it's just
Copy code
inject name='print' injet='printBuffer';
❤️ 1
j
Better than printBuffer=inkjet
1
r
Working like a champ. Thanks Brad
👍 1
lol I knew what he was inferring 😉
b
That's the same thing that gets injected into every task runner or custom command. The only difference is, in those cases, any remaining text left in the buffer is flushed out at the end of the task/command. When you inject your own, it's entirely up to you to flush it out when you want.
r
Fair enough. Thanks for you time/patience