Revision 0c1833c8 snf-tools/synnefo_tools/burnin/logger.py

b/snf-tools/synnefo_tools/burnin/logger.py
207 207

  
208 208
    """
209 209
    # ----------------------------------
210
    # Too many arguments. pylint: disable-msg=R0913
210 211
    def __init__(self, output_dir, verbose=1, use_colors=True,
211
                 in_parallel=False):
212
                 in_parallel=False, quiet=False):
212 213
        """Initialize our loggers
213 214

  
214 215
        The file to be used by our file logger will be created inside
......
225 226
        @param use_colors: use colors for out stdout/stderr logger
226 227
        @type in_parallel: boolean
227 228
        @param in_parallel: this signifies that burnin is running in parallel
229
        @type quiet: boolean
230
        @type quiet: do not print logs to stdout/stderr
228 231

  
229 232
        """
230 233
        self.verbose = verbose
231 234
        self.use_colors = use_colors
232 235
        self.in_parallel = in_parallel
236
        self.quiet = quiet
233 237

  
234 238
        assert output_dir
235 239

  
......
252 256

  
253 257
        timestamp = datetime.datetime.strftime(
254 258
            datetime.datetime.now(), "%a %b %d %Y %H:%M")
255
        sys.stdout.write("Starting burnin (%s)\n" % timestamp)
259
        self._write_to_stdout(None, "Starting burnin (%s)\n" % timestamp)
256 260

  
257 261
        # Create the logging file
258 262
        self._create_logging_file(timestamp)
......
278 282
            except OSError:
279 283
                self.debug(None, "Couldn't delete lock file")
280 284

  
285
    def print_logfile_to_stdout(self):
286
        """Print the contents of our log file to stdout"""
287
        with open(self.file_location, 'r') as fin:
288
            sys.stdout.write(fin.read())
289

  
281 290
    # ----------------------------------
282 291
    # Logging methods
283 292
    def debug(self, section, msg, *args):
......
346 355

  
347 356
    def _write_to_stdout(self, section, msg):
348 357
        """Write to stdout"""
349
        if section is not None and self.in_parallel:
350
            sys.stdout.write(section + ": " + msg)
351
        else:
352
            sys.stdout.write(msg)
358
        if not self.quiet:
359
            if section is not None and self.in_parallel:
360
                sys.stdout.write(section + ": " + msg)
361
            else:
362
                sys.stdout.write(msg)
353 363

  
354 364
    def _write_to_stderr(self, section, msg):
355 365
        """Write to stderr"""
356
        if section is not None and self.in_parallel:
357
            sys.stderr.write(section + ": " + msg)
358
        else:
359
            sys.stderr.write(msg)
366
        if not self.quiet:
367
            if section is not None and self.in_parallel:
368
                sys.stderr.write(section + ": " + msg)
369
            else:
370
                sys.stderr.write(msg)
360 371

  
361 372
    def _write_to_file(self, section, msg):
362 373
        """Write to file"""

Also available in: Unified diff