Set release details for 2.2.20
[clive.git] / lib / clive / Log.pm
blob1171ec9652b8fe4589d21e33b60450117b0af299
1 # -*- coding: ascii -*-
2 ###########################################################################
3 # clive, command line video extraction utility.
5 # Copyright 2009 Toni Gundogdu.
7 # This file is part of clive.
9 # clive is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU General Public License as published by the Free
11 # Software Foundation, either version 3 of the License, or (at your option)
12 # any later version.
14 # clive is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 # details.
19 # You should have received a copy of the GNU General Public License along
20 # with this program. If not, see <http://www.gnu.org/licenses/>.
21 ###########################################################################
22 package clive::Log;
24 use warnings;
25 use strict;
27 use base 'Class::Singleton';
29 use clive::Error qw(CLIVE_OK);
31 sub init {
32 my $self = shift;
34 $self->{return_code} = CLIVE_OK;
36 my $config = clive::Config->instance->config;
37 $self->{quiet} = $config->{quiet};
39 # Go unbuffered.
40 select STDERR;
41 $| = 1;
42 select STDOUT;
43 $| = 1;
46 sub out {
47 my $self = shift;
48 return if $self->{quiet};
50 my $ref
51 = clive::Config->instance->config->{stderr}
52 ? \*STDERR
53 : \*STDOUT;
55 my $fmt = shift;
56 my $str = @_ ? sprintf( $fmt, @_ ) : $fmt;
58 print $ref $str;
61 sub err {
62 my $self = shift;
63 $self->{return_code} = shift;
65 return if $self->{quiet};
67 my $fmt = shift;
68 my $msg = "error: " . ( @_ ? sprintf( $fmt, @_ ) : $fmt );
70 print( STDERR "$msg\n" );
73 sub errn {
74 my $self = shift;
76 print( STDERR "\n" )
77 if ( !$self->{quiet} );
79 err ( $self, @_ );
82 sub returnCode {
83 my $self = shift;
84 return $self->{return_code};
89 # All along the watchtower.