line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Netdata::Util; |
2
|
5
|
|
|
5
|
|
226821
|
use Mojo::Base -strict, -signatures; |
|
5
|
|
|
|
|
163061
|
|
|
5
|
|
|
|
|
33
|
|
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
4905
|
use overload (); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
135
|
|
5
|
5
|
|
|
5
|
|
27
|
use Exporter qw(import); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
149
|
|
6
|
5
|
|
|
5
|
|
1580
|
use Mojo::File; |
|
5
|
|
|
|
|
99221
|
|
|
5
|
|
|
|
|
311
|
|
7
|
5
|
|
|
5
|
|
2492
|
use Mojo::JSON qw(encode_json); |
|
5
|
|
|
|
|
115789
|
|
|
5
|
|
|
|
|
2324
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(logf safe_id); |
10
|
|
|
|
|
|
|
our $STDERR = \*STDERR; # useful for testing |
11
|
|
|
|
|
|
|
|
12
|
28
|
|
|
28
|
1
|
7647
|
sub logf ($level, $format, @args) { |
|
28
|
|
|
|
|
53
|
|
|
28
|
|
|
|
|
43
|
|
|
28
|
|
|
|
|
53
|
|
|
28
|
|
|
|
|
39
|
|
13
|
28
|
100
|
66
|
|
|
150
|
return 1 if $ENV{HARNESS_ACTIVE} and !$ENV{HARNESS_IS_VERBOSE}; |
14
|
6
|
100
|
66
|
|
|
28
|
return 1 if $level eq 'debug' and !($ENV{NETDATA_DEBUG} || $ENV{HARNESS_IS_VERBOSE}); |
|
|
|
100
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
|
|
11
|
my $module_name = caller; |
17
|
5
|
|
|
|
|
144
|
my ($s, $m, $h, $day, $month, $year) = localtime time; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
25
|
state $program_name = Mojo::File->new($0)->basename; |
20
|
5
|
|
|
|
|
30
|
printf {$STDERR} "%s-%02s-%02s %02s:%02s:%02s: %s: %s: %s: $format\n", $year + 1900, $month + 1, |
21
|
|
|
|
|
|
|
$day, $h, $m, $s, $program_name, uc $level, $module_name, |
22
|
5
|
100
|
100
|
|
|
117
|
map { overload::Method($_, q("")) ? "$_" : !defined $_ || ref $_ ? encode_json $_ : $_ } @args; |
|
5
|
100
|
|
|
|
58
|
|
23
|
5
|
|
|
|
|
1086
|
return 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
88
|
|
|
88
|
1
|
3819
|
sub safe_id ($str) { |
|
88
|
|
|
|
|
115
|
|
|
88
|
|
|
|
|
111
|
|
27
|
88
|
|
|
|
|
345
|
$str =~ s![^A-Za-z0-9]!_!g; |
28
|
88
|
|
|
|
|
207
|
$str =~ s!_+$!!g; |
29
|
88
|
|
|
|
|
144
|
$str =~ s!^_+!!g; |
30
|
88
|
|
|
|
|
260
|
return $str; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=encoding utf8 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Mojo::Netdata::Util - Utility functions for Mojo::Netdata |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use Mojo::Netdata::Util qw(safe_id); |
44
|
|
|
|
|
|
|
print safe_id 'Not%co.ol'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
L as functions that can be useful when working with |
49
|
|
|
|
|
|
|
L classes. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 logf |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
logf $level, $format, @args; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Used to log messages to STDERR. C<$level> can be "debug", "info", "warnings", |
58
|
|
|
|
|
|
|
"error", "fatal". Any references and undefined values in C<@args> will be |
59
|
|
|
|
|
|
|
serialized using L. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 safe_id |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$str = safe_id $str; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Turns an "unsafe" string into a string you can use for things like "id" or |
66
|
|
|
|
|
|
|
"type". This is called by L and |
67
|
|
|
|
|
|
|
L to make sure the output strings are |
68
|
|
|
|
|
|
|
safe. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SEE ALSO |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
L. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |