Debug and Verbose colouring

Home  >>  Hint  >>  Debug and Verbose colouring

Debug and Verbose colouring

On January 29, 2007, Posted by , In Hint,PowerShell, With 2 Comments

Over the weekend, I set about writing an IRC chat client/channel monitoring tool in PowerShell (more on that in a day or so) and one of the things I was doing a lot was writing verbose and debug information to the console.

By default, Write-Verbose and Write-Debug cmdlets write nothing to the console, because the the value of the variables $VerbosePreference and $DebugPreference respectively are “SilentlyContinue”.

If you set them both to “Continue” the text is written to the console, but both in bright yellow on black (I wonder why?), like this:

PS> $DebugPreference="continue"
PS> $VerbosePreference="continue"
PS> write-debug "debug msg"
DEBUG: debug msg
PS> write-verbose "verbose msg"
VERBOSE: verbose msg

These colours can be changed so you can more easily distinguish between debug and verbose messages, and also not have the real output swamped.

The trick is to change the values of the colours in $host.privatedata, and I do this:


# normal colours

# error colours

# warning colours

# debug colours

# verbose colours

# progress colours

Now, the IRC app I’m working on, when I run with debug/verbose switched on, yields an output like this:

PS> test
DEBUG: Using connection info:
DEBUG: port: 6667
DEBUG: nick: soapybot
DEBUG: server:
DEBUG: hostname: localhost
DEBUG: user: soapybot
DEBUG: realname: inout-irc as soapybot
VERBOSE: >> NICK soapybot
VERBOSE: >> USER soapybot localhost :inout-irc as soapybot
VERBOSE: << NOTICE AUTH :*** Looking up your hostname...
VERBOSE: << NOTICE AUTH :*** Found your hostname, welcome back
VERBOSE: << NOTICE AUTH :*** Checking ident
VERBOSE: << NOTICE AUTH :*** No identd (auth) response
VERBOSE: << 001 soapybot :Welcome to the freenode IRC Network 
VERBOSE: << 002 soapybot :Your host is[], running version hyperion-1.0.2b
VERBOSE: << NOTICE soapybot :*** Your host is[], running version hyperion-1.0.2b
VERBOSE: << 003 soapybot :This server was created Fri Dec 22 
00:07:52 UTC 2006
VERBOSE: << 004 soapybot hyperion-1.0.2b 
aAbBcCdDeEfFGhHiIjkKlLmMnNopPQrRsStTuUvVwWxXyYzZ01234569*@ bcdefFhiIklmnoPqstv
 CHANMODES=bdeIq,k,lfJD,cgijLmnPQrRstz CHANLIMIT=#:20 PREFIX=(ov)@+ MAXLIST=bdeI:50 
MODES=4 STATUSMSG=@ KNOCK NICKLEN=16 :are supported by this server
TOPICLEN=450 KICKLEN=450 KEYLEN=23 USERLEN=10 HOSTLEN=63 SILENCE=50 :are supported by 
this server
VERBOSE: << 251 soapybot :There are 18601 listed and 16168 unlisted 
users on 24 servers
VERBOSE: << 375 soapybot :- Message of the Day - 
VERBOSE: << 372 soapybot :- Freenode is a service of Peer-Directed 
Projects Center, an
VERBOSE: << 372 soapybot :- IRS 501(c)(3) not-for-profit 
organization.  Our yearly
VERBOSE: << 372 soapybot :- fundraiser will begin soon; if you'd 
like to donate early,
VERBOSE: << 372 soapybot :- please see for more
VERBOSE: << 372 soapybot :- information.  Thank you for using 
VERBOSE: << 372 soapybot :- 
VERBOSE: << 376 soapybot :End of /MOTD command.
VERBOSE: >> JOIN #test,#test2,#archlinux
VERBOSE: << :freenode-connect!freenode@freenode/bot/connect PRIVMSG soapybot :☺VERSION☺
freenode-connect : soapybot : VERSION
VERBOSE: << :soapybot!n=soapybot@*********** JOIN :#test
DEBUG: We may have joined channel #test
VERBOSE: << 332 soapybot #test :Welcome to #test - This channel is 
for testing only. Don't harass or annoy other users here. Don't paste senceless crap 
here. If you need a response for tests type '#say foobar' or '#moo' - Have a nice time 
in here... RIP lilo aka rob levin :'(
DEBUG: We have joined channel #test
VERBOSE: << :soapybot!n=soapybot@*************** JOIN :#test2
DEBUG: We may have joined channel #test2
VERBOSE: >> PRIVMSG #test2 :hello
VERBOSE: << :soapybot!n=soapybot@*************** JOIN :#archlinux
DEBUG: We may have joined channel #archlinux
VERBOSE: << 332 soapybot #archlinux :[ Welcome to #archlinux! 
(!rules) || main: || forums: || wiki:
 || bugs: || AUR: || iso: ]
DEBUG: We have joined channel #archlinux
VERBOSE: << :schnappi!n=joy@debiancenter/user/schnappi PRIVMSG #test :Good after-noon, 
soapybot. It's 17:28h.GMT
schnappi : #test : Good after-noon, soapybot. It's 17:28h.GMT
VERBOSE: << :Danny|! PART #archlinux :"So Say We
VERBOSE: << :millinad!n=millinad@*************** PRIVMSG #test2 :hello 
millinad : #test2 : hello soapybot
VERBOSE: << :millinad!n=millinad@*************** PRIVMSG #test2 :go now
millinad : #test2 : go now
VERBOSE: << :millinad!n=millinad@*************** PRIVMSG #test2 :wibble
millinad : #test2 : wibble
VERBOSE: >> PART #test2
VERBOSE: >> PART #archlinux
VERBOSE: >> PART #test
VERBOSE: >> QUIT :bye bye

(some of the above has been trimmed for clarity and privacy).

The brighter white output is the normal output from the script, the grey is debug messages and cyan, verbose. It gives me all the output I want, without making it too hard to pick out the real information.

Once I’m happy that all is well, I can revert the $VerbosePreference and $DebugPreference variables back to “SilentlyContinue” and all you get is the default white output.

2 Comments so far:

  1. […] chat bot and monitorDebug and Verbose colouringMaking functions *really* read-onlyUpdated get-bufferhtmlWebserver and RSH in […]