Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Some minor edits to MCP and mlog.pm

  • Loading branch information...
commit 0b8bfcb144d02a5b91c1fb3595f789d64eb09f28 1 parent 496f34a
jaredbischof authored

Showing 2 changed files with 31 additions and 28 deletions. Show diff stats Hide diff stats

  1. +1 1  MCP
  2. +30 27 mlog_libs/mlog.pm
2  MCP
@@ -10,7 +10,7 @@ from ConfigParser import SafeConfigParser
10 10 # Getting paths
11 11 MCP_path = os.path.realpath(__file__)
12 12 matchObj = re.match(r'(^.*\/)', MCP_path)
13   -MCP_dir = matchObj.group()
  13 +MCP_dir = matchObj.group(0)
14 14
15 15 # Adding modules directory to path
16 16 path = list(sys.path)
57 mlog_libs/mlog.pm
@@ -15,7 +15,7 @@ use Sys::Syslog qw( :DEFAULT setlogsock);
15 15
16 16 require Exporter;
17 17
18   -my $mlog_conf_file = "/etc/mlog/mlog.conf";
  18 +my $MLOG_CONF_FILE = "/etc/mlog/mlog.conf";
19 19 my $DEFAULT_LOG_LEVEL = 6;
20 20 my $MSG_CHECK_COUNT = 100;
21 21 my $MSG_CHECK_INTERVAL = 300; # 300s = 5min
@@ -38,7 +38,7 @@ mlog
38 38
39 39 =head1 DESCRIPTION
40 40
41   -A wrapper for sending MGRAST logging to syslog.
  41 +A library for sending MG-RAST logging to syslog.
42 42
43 43 =head1 METHODS
44 44
@@ -48,7 +48,7 @@ logit(level, component, message, error_code): sends mgrast log message to syslog
48 48
49 49 =over 10
50 50
51   -=item * level: (0-6) The logging level for this message is compared to the logging level that has been set in MGRAST_syslog. If it is <= the set logging level, the message will be sent to syslog, otherwise it will be ignored. Logging level is set to 6 if MGRAST control API cannot be reached.
  51 +=item * level: (0-6) The logging level for this message is compared to the logging level that has been set in mlog. If it is <= the set logging level, the message will be sent to syslog, otherwise it will be ignored. Logging level is set to 6 if MG-RAST control API cannot be reached.
52 52
53 53 =item * component: (string) This is the utility within MG-RAST that is logging the message. This is a free text field.
54 54
@@ -90,33 +90,16 @@ use_api_log_level(string component) : Removes the user-defined log level for thi
90 90
91 91 =cut
92 92
93   -sub _get_log_level {
94   - my ($component) = @_;
95   - if(exists $user_defined_log_levels{$component}) {
96   - return $user_defined_log_levels{$component};
97   - } elsif(exists $api_defined_log_levels{$component}) {
98   - return $api_defined_log_levels{$component};
99   - } else {
100   - return $DEFAULT_LOG_LEVEL;
101   - }
102   -}
103   -
104   -sub _get_time_since_start {
105   - my $now = DateTime->now( time_zone => 'local' )->set_time_zone('floating');
106   - my $seconds_duration = $now->subtract_datetime_absolute($last_update_time);
107   - return $seconds_duration->seconds;
108   -}
109   -
110 93 sub init_mlog {
111 94 $last_update_msg_count = 0;
112 95 $last_update_time = DateTime->now( time_zone => 'local' )->set_time_zone('floating');
113 96
114 97 # Retrieving the control API defined log levels...
115 98 my $api_mlog_url = "";
116   - open IN, "$mlog_conf_file" || print STDERR "Cannot open $mlog_conf_file for reading mlog configuration.\n";
  99 + open IN, "$MLOG_CONF_FILE" || print STDERR "Cannot open $MLOG_CONF_FILE for reading mlog configuration.\n";
117 100 while(my $line=<IN>) {
118 101 chomp $line;
119   - if($line =~ /^url.*$/) {
  102 + if($line =~ /^url\s+.*$/) {
120 103 my @array = split(/\s+/, $line);
121 104 $api_mlog_url = $array[1];
122 105 }
@@ -136,6 +119,23 @@ sub init_mlog {
136 119 return 1;
137 120 }
138 121
  122 +sub _get_log_level {
  123 + my ($component) = @_;
  124 + if(exists $user_defined_log_levels{$component}) {
  125 + return $user_defined_log_levels{$component};
  126 + } elsif(exists $api_defined_log_levels{$component}) {
  127 + return $api_defined_log_levels{$component};
  128 + } else {
  129 + return $DEFAULT_LOG_LEVEL;
  130 + }
  131 +}
  132 +
  133 +sub _get_time_since_start {
  134 + my $now = DateTime->now( time_zone => 'local' )->set_time_zone('floating');
  135 + my $seconds_duration = $now->subtract_datetime_absolute($last_update_time);
  136 + return $seconds_duration->seconds;
  137 +}
  138 +
139 139 sub set_log_level {
140 140 my ($level, $component) = @_;
141 141 if($level !~ /^\d+$/ || $component eq "") {
@@ -186,16 +186,19 @@ sub logit {
186 186 return 0;
187 187 }
188 188
189   - if($msg_count == 0 && $last_update_time eq "") {
190   - print STDERR "WARNING: mlog_init() was not called, so I will call it for you.\n";
191   - mlog_init();
192   - }
193   -
194 189 unless($level =~ /^\d+$/ && $level >= 0 && $level <= 6) {
195 190 print STDERR "ERROR: mlog level '$level' is invalid, you must enter an integer between 0 and 6, inclusive.\n";
196 191 return 0;
197 192 }
198 193
  194 + ++$msg_count;
  195 + ++$last_update_msg_count;
  196 +
  197 + if($msg_count == 0 && $last_update_time eq "") {
  198 + print STDERR "WARNING: mlog_init() was not called, so I will call it for you.\n";
  199 + mlog_init();
  200 + }
  201 +
199 202 # May want to include these in 1st openlog argument
200 203 my $user = $ENV{'USER'};
201 204 my $ident = abs_path($0);

0 comments on commit 0b8bfcb

Please sign in to comment.
Something went wrong with that request. Please try again.