#!perl -T
{
my
$file
=
"fine.log"
;
my
$msg
=
"We're so miserable it's stunning"
;
my
$log
= Log::Fine->logger(
"handlefile0"
);
isa_ok(
$log
,
"Log::Fine::Logger"
);
can_ok(
$log
,
"name"
);
ok(
$log
->name() =~ /\w\d+$/);
my
$handle
=
Log::Fine::Handle::File->new(
file
=>
$file
,
autoflush
=> 1);
isa_ok(
$handle
,
"Log::Fine::Handle"
);
can_ok(
$handle
,
"name"
);
can_ok(
$handle
,
"levelMap"
);
can_ok(
$handle
,
"msgWrite"
);
ok(
$handle
->name() =~ /\w\d+$/);
ok(
$handle
->{mask} ==
$handle
->levelMap()->bitmaskAll());
ok(
$handle
->{formatter}->isa(
"Log::Fine::Formatter::Basic"
));
ok(
$handle
->{file} eq
$file
);
ok(
$handle
->{dir} eq
"./"
);
ok(
$handle
->{autoflush} == 1);
ok(
$handle
->{autoclose} == 0);
unlink
$file
if
-e
$file
;
$handle
->msgWrite(INFO,
$msg
, 1);
my
$fh
=
$handle
->fileHandle();
isa_ok(
$fh
,
"IO::File"
);
ok(-e
$file
);
$fh
->
close
();
$fh
= FileHandle->new(catdir(
$handle
->{dir},
$file
));
isa_ok(
$fh
,
"IO::File"
);
while
(<
$fh
>) {
ok(/^\[.*?\] \w+
$msg
/);
}
$fh
->
close
();
unlink
$file
;
my
$closehandle
=
Log::Fine::Handle::File->new(
file
=>
$file
,
autoflush
=> 1,
autoclose
=> 1
);
isa_ok(
$closehandle
,
"Log::Fine::Handle::File"
);
can_ok(
$closehandle
,
"fileHandle"
);
can_ok(
$closehandle
,
"msgWrite"
);
my
$fh2
=
$closehandle
->fileHandle();
$closehandle
->msgWrite(INFO,
$msg
, 1);
ok(not
defined
fileno
$fh2
);
unlink
$file
;
my
(
$tempfh
,
$tmpfile
) = mkstemp(
"logfinehandletmpXXXXXX"
);
ok(
defined
$tmpfile
);
$tempfh
->
close
();
my
$tmphandle
=
Log::Fine::Handle::File->new(
file
=>
$tmpfile
,
autoflush
=> 1);
isa_ok(
$tmphandle
,
"Log::Fine::Handle::File"
);
my
$fh3
=
$tmphandle
->fileHandle();
isa_ok(
$fh3
,
"FileHandle"
);
$tmphandle
->msgWrite(DEBG,
$msg
, 1);
ok(-f
$tmpfile
);
$fh3
->
close
();
unlink
$tmpfile
;
}