ollyg / Net-Appliance-Session

Development of Net::Appliance::Session Perl distribution
https://metacpan.org/pod/Net::Appliance::Session
13 stars 6 forks source link

'old school' user porting from 1.36 #17

Closed StingRayZA closed 11 years ago

StingRayZA commented 11 years ago

Hi

I'm a longtime user of N::A::S and am finally taking the plunge to upgrade from the 'old' 1.36...

I have the two following issues/queries:

  1. I used to use the input_log function in the constructor to output the session log to a file where my users could inspect it. How would I do something similar with the new Log system?
  2. I'm trying to move away from my eval constructs to the simpler (and more preferable) Try::Tiny syntax, however, it seems to not be working as expected (or am I expecting something strange?). Given the following code ($session is a new N::A::S object that I've just created), the $session method succeeds, but then the catch block is still executed. as a result, I'm having to just drop the try/catches for now and complete porting without them... Any ideas what the issue could be?
my $connectParams = {
    username            => $userName,
    password            => $userPass,
};

try {
    $session->connect($connectParams);
}
catch {
    $$error .=  "ERROR~=Cannot Connect to PE";
    $retval = 0;
};
ollyg commented 11 years ago

Sorry for not acknowledging your issue sooner, for some reason I didn't receive an email copy from GitHub. I'll take a look and reply soon.

ollyg commented 11 years ago

Hi,

About the logging, there wasn't a lot of documentation about the new logging system, but that should now be addressed with a new section in the Cookbook for Net::CLI::Interact. I've just uploaded version 2.123612 to CPAN.

Unfortunately I can't reproduce the issue you have with the try/catch blocks. Perhaps you can look at the new logging system and enable debug level, to see if anything odd is happening when you call the connect() method? It's most easily done by setting the NCI_LOG_AT=debug environment variable before running the test script.

Please let me know how you get on.

regards, oliver.

StingRayZA commented 11 years ago

Hi Oliver

Thanks for coming back to me... Don't stress about the delay - I've just returned from a Christmas/New Year break myself.

I've had a quick look at the new Cookbook section. It looks like it'll answer most of my queries, however, I'd still like to be able to write just the session output to a file (and perhaps the full log to another file/destination). Running the script with full debug output generates the module's internal log output - which is great for me, but a little too verbose for my users. Also in that output is credentials free for all to see. (Granted, if anybody knows how to look, they'll find them accessed in the script itself, but I've heavily obfuscated them there, so they're at least harder to find).

In terms of the try/catch problem I was having, it seems it doesn't like perl debug mode. I'm a heavy user of 'perl -d script' when extending and tweaking my code - and it seems that's where much of the issues were occurring. When trying a simple try/catch script, it seemed to work perfectly when just being executed, but break when using the debugger. It seems like this is more of an issue with try/catch. I've stuck to evals for now until I can work out how to get around this.

In any case, I managed to complete my port, and managed to even get a bit of refactoring done in my own code. Getting the session output working wasn't essential to the project, but it would still very much be a 'nice to have'.

Regards Raimund

ollyg commented 11 years ago

You should be able to have different log levels for different destinations. The log level in Net::Appliance::Session controls what is sent to all Log::Dispatch destinations. (so you might want this at debug)

Then, each destination can set its own levels "filter". The options are min_level and max_level, I believe.

Hope this helps...