Skip to content

Log R4.2 API

Gentilhomme edited this page Mar 2, 2017 · 3 revisions

Logger

API for perluim release 4.2 or higher.

Log class is able to reproduce the original nimLog behavior. But my log system it's a lot better if you want a good trace in time (without crossing all logs).

use perluim::logger;
use perluim::main;

my $time = time();
my $Logger;
$Logger = new perluim::logger({
    file => "test_probe.log",
    level => 5
});
$Logger->log(3,'test_probe started!');

# Do the job here !

# Close the log!
$Logger->finalTime($time);
$Logger->copyTo('output');

R3.0 Is now including Auto-flush.

Loglevel

Level Header
0 Critical
1 Error
2 Warning
3 Info
4 Debug
5 Empty
6 Success

Constructor

The log constructor take four argument :

  • file : The name of the log.
  • level : The level of the log.
  • size : The maximum size of the log (put 0 if you want no maximum logsize).
  • rewrite : Rewrite configuration on startup. (Put no if you want nimLog behavior with log size).

API

setLevel(level: number)

Reconfigure / set loglevel

$Logger->setLevel($CFG->{setup}->{loglevel});

close()

Close logfile.


print(level: number,message: string)

$Logger->log(3,'Hello world!');
$Logger->log(0,'Critical error!');

dateLog()

Return CA UIM formatted date!

Exemple : Nov 22 09:58:06


cleanDirectory(path: string,maxAge: number)

Clean directories when the time is outdated.

maxAge is second

$Logger->cleanDirectory('output',4000); 

finalTime(timer: timer)

Print the final execution time.

my $ScriptExecutionTime = time(); 
# Script here 
$Logger->finalTime($ScriptExecutionTime);

return something like that Final execution time = 0.00 second(s) [0.00 minutes]!


copyTo(directoryPath: string)

Copy the logfile to a another destination !

Warning copyTo method close the log file.

my $ExecutionDate = $SDK->getDate();
$SDK->createDirectory("output/$ExecutionDate");
$Logger->copyTo("output/$ExecutionDate");