PLace dubug messages in code

English! place to talk about development, programming and coding
Post Reply
rodolfor
Znuny newbie
Posts: 89
Joined: 11 Jun 2020, 14:56
Znuny Version: 6.0.27
Real Name: Rodolfo Rughi
Company: none

PLace dubug messages in code

Post by rodolfor »

Hi all.
I'm new to Linux and perl developing.
Where I can put debug log messages inside otrs code?
And where can I see them?

Thanks
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: PLace dubug messages in code

Post by zzz »

Hello,

You can use the Data::Dumper.
Put this inside your code and replace the variables you want to dump.

Code: Select all

print Data::Dumper->Dump([$Scalar, \@Array, \%Hash]);
Check the error log of your web server.
Don't use your production system.

— Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
rodolfor
Znuny newbie
Posts: 89
Joined: 11 Jun 2020, 14:56
Znuny Version: 6.0.27
Real Name: Rodolfo Rughi
Company: none

Re: PLace dubug messages in code

Post by rodolfor »

Thanks zzz!
Yeti
Znuny newbie
Posts: 10
Joined: 24 Jan 2018, 11:58
Znuny Version: All
Real Name: Tim
Company: maxence business consulting GmbH
Location: Dormagen
Contact:

Re: PLace dubug messages in code

Post by Yeti »

To extend a bit on Emins post, you can use

Code: Select all

print STDERR Data::Dumper->Dump([(caller(0))[3] . ' Line:' . __LINE__ , \ $TestValue ]);
to also get the file and line you dump is coming from.
maxence business consulting gmbh
http://www.maxence.de
41. OTRS Community Treffen Rheinland: klick
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: PLace dubug messages in code

Post by reneeb »

If you want the debug output in the same log as other OTRS logs, you should use

Code: Select all

$Kernel::OM->Get('Kernel::System::Log')->Log( Priority => error => Message => $Kernel::OM->Get('Kernel::System::Main')->Dump( [1,2,3] ) );
And when you want to use the other proposed code snippets, I would recommend to use Data::Printer as it sorts keys of hashes automatically and it has a more compact format. But you might need to install the module...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Post Reply