PLace dubug messages in code

English! place to talk about development, programming and coding
Post Reply
rodolfor
OTRS newbie
Posts: 35
Joined: 11 Jun 2020, 14:56
OTRS 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
OTRS superhero
Posts: 677
Joined: 15 Dec 2016, 15:13
OTRS Version?: 3.x–6.0.x
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 & ((OTRS)) Community Edition services: efflux.de | efflux.de/en/

Free and premium OTRS add-ons: German | English

rodolfor
OTRS newbie
Posts: 35
Joined: 11 Jun 2020, 14:56
OTRS Version?: 6.0.27
Real Name: Rodolfo Rughi
Company: none

Re: PLace dubug messages in code

Post by rodolfor »

Thanks zzz!

Yeti
OTRS newbie
Posts: 10
Joined: 24 Jan 2018, 11:58
OTRS Version?: 6.0.4
Real Name: Tim
Company: maxence business consulting GmbH
Location: Dormagen

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
OTRS guru
Posts: 4808
Joined: 13 Mar 2011, 09:54
OTRS Version?: 3.3.x
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 / OTRS development: http://perl-services.de
Free OTRS add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de

Post Reply