mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2024-11-12 13:56:27 +01:00
62 lines
1.2 KiB
Perl
62 lines
1.2 KiB
Perl
|
package Basework;
|
||
|
#
|
||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||
|
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||
|
#
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
use POSIX;
|
||
|
use CGI; # only for debugging
|
||
|
use Lib::Config;
|
||
|
|
||
|
use Data::Dumper;
|
||
|
use Sys::Hostname;
|
||
|
my $hostname = hostname;
|
||
|
my $cf = new Config;
|
||
|
my $q = new CGI;
|
||
|
|
||
|
sub new {
|
||
|
my $class = shift;
|
||
|
my $self = {};
|
||
|
bless($self,$class);
|
||
|
return $self;
|
||
|
}
|
||
|
|
||
|
my $time = time;
|
||
|
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
||
|
my $now_date = strftime "%Y-%m-%d", localtime;
|
||
|
|
||
|
|
||
|
#logging
|
||
|
sub log {
|
||
|
my $self = shift;
|
||
|
my ($what,$message,$stdout) = @_;
|
||
|
#my ($package, $filename, $line) = caller;
|
||
|
my %varenv = $cf->envonline();
|
||
|
|
||
|
$now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
||
|
my $logfile = "/var/log/copri4/$varenv{syshost}-process.log";
|
||
|
if($varenv{debug}){
|
||
|
warn "$what" . "\n" . Dumper($message) . "\n";#to apache2/error.log
|
||
|
|
||
|
#2021-07-21 disabled. error.log is enough
|
||
|
if(1==2){
|
||
|
open(FILE,">> $logfile");
|
||
|
print FILE "\n--- $now_dt $0 ---\n";
|
||
|
print FILE "$what" . "\n" . Dumper($message) . "\n";
|
||
|
close FILE;
|
||
|
}
|
||
|
#also to stdout
|
||
|
if($stdout){
|
||
|
#print "\n--- $now_dt $0 ---\n";
|
||
|
print "$what" . "\n" . Dumper($message) . "\n";
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
1;
|