github.com/getgauge/gauge@v1.6.9/logger/gaugeLogger.go (about)

     1  // Copyright 2019 ThoughtWorks, Inc.
     2  
     3  /*----------------------------------------------------------------
     4   *  Copyright (c) ThoughtWorks, Inc.
     5   *  Licensed under the Apache License, Version 2.0
     6   *  See LICENSE in the project root for license information.
     7   *----------------------------------------------------------------*/
     8  
     9  package logger
    10  
    11  import (
    12  	"fmt"
    13  	"os"
    14  )
    15  
    16  // Info logs INFO messages. stdout flag indicates if message is to be written to stdout in addition to log.
    17  func Info(stdout bool, msg string) {
    18  	logInfo(loggersMap.getLogger(gaugeModuleID), stdout, msg)
    19  }
    20  
    21  // Infof logs INFO messages. stdout flag indicates if message is to be written to stdout in addition to log.
    22  func Infof(stdout bool, msg string, args ...interface{}) {
    23  	Info(stdout, fmt.Sprintf(msg, args...))
    24  }
    25  
    26  // Error logs ERROR messages. stdout flag indicates if message is to be written to stdout in addition to log.
    27  func Error(stdout bool, msg string) {
    28  	logError(loggersMap.getLogger(gaugeModuleID), stdout, msg)
    29  }
    30  
    31  // Errorf logs ERROR messages. stdout flag indicates if message is to be written to stdout in addition to log.
    32  func Errorf(stdout bool, msg string, args ...interface{}) {
    33  	Error(stdout, fmt.Sprintf(msg, args...))
    34  }
    35  
    36  // Warning logs WARNING messages. stdout flag indicates if message is to be written to stdout in addition to log.
    37  func Warning(stdout bool, msg string) {
    38  	logWarning(loggersMap.getLogger(gaugeModuleID), stdout, msg)
    39  }
    40  
    41  // Warningf logs WARNING messages. stdout flag indicates if message is to be written to stdout in addition to log.
    42  func Warningf(stdout bool, msg string, args ...interface{}) {
    43  	Warning(stdout, fmt.Sprintf(msg, args...))
    44  }
    45  
    46  // Fatal logs CRITICAL messages and exits. stdout flag indicates if message is to be written to stdout in addition to log.
    47  func Fatal(stdout bool, msg string) {
    48  	logCritical(loggersMap.getLogger(gaugeModuleID), msg)
    49  	addFatalError(gaugeModuleID, msg)
    50  	write(stdout, getFatalErrorMsg(), os.Stdout)
    51  	os.Exit(1)
    52  }
    53  
    54  // Fatalf logs CRITICAL messages and exits. stdout flag indicates if message is to be written to stdout in addition to log.
    55  func Fatalf(stdout bool, msg string, args ...interface{}) {
    56  	Fatal(stdout, fmt.Sprintf(msg, args...))
    57  }
    58  
    59  // Debug logs DEBUG messages. stdout flag indicates if message is to be written to stdout in addition to log.
    60  func Debug(stdout bool, msg string) {
    61  	logDebug(loggersMap.getLogger(gaugeModuleID), stdout, msg)
    62  }
    63  
    64  // Debugf logs DEBUG messages. stdout flag indicates if message is to be written to stdout in addition to log.
    65  func Debugf(stdout bool, msg string, args ...interface{}) {
    66  	Debug(stdout, fmt.Sprintf(msg, args...))
    67  }
    68  
    69  // HandleWarningMessages logs multiple messages in WARNING mode
    70  func HandleWarningMessages(stdout bool, warnings []string) {
    71  	for _, warning := range warnings {
    72  		Warning(stdout, warning)
    73  	}
    74  }