github.com/vmware/go-vcloud-director/v2@v2.24.0/util/LOGGING.md (about)

     1  # LOGGING
     2  
     3  
     4  ## Defaults for logging
     5  
     6  Use of the standard Go `log` package is deprecated and should be avoided. 
     7  The recommended way of logging is through the logger `util.Logger`, which supports [all the functions normally available to `log`](https://golang.org/pkg/log/#Logger).
     8  
     9  
    10  By default, **logging is disabled**. Any `Logger.Printf` statement will simply be discarded.
    11  
    12  To enable logging, you should use
    13  
    14  ```go
    15  util.EnableLogging = true
    16  util.SetLog()
    17  ```
    18  
    19  When enabled, the default output for logging is a file named `go-vcloud-director.log`.
    20  The file name can be changed using
    21  
    22  ```go
    23  util.ApiLogFileName = "my_file_name.log"
    24  ```
    25  
    26  
    27  If you want logging on the screen, use
    28  
    29  ```go
    30  util.Logger.SetOutput(os.Stdout)
    31  ```
    32  
    33  or
    34  
    35  ```
    36  util.Logger.SetOutput(os.Stderr)
    37  ```
    38  
    39  ## Automatic logging of HTTP requests and responses.
    40  
    41  The HTTP requests and responses are automatically logged.
    42  Since all the HTTP operations go through `NewRequest` and `decodeBody`, the logging captures the input and output of the request with calls to `util.ProcessRequestOutput` and `util.ProcessResponseOutput`.
    43  
    44  These two functions will show the request or response, and the function from which they were called, giving devs an useful tracking tool.
    45  
    46  The output of these functions can be quite large. If you want to mute the HTTP processing, you can use:
    47  
    48  ```go
    49  util.LogHttpRequest = false
    50  util.LogHttpResponse = false
    51  ```
    52  
    53  During the request and response processing, any password or authentication token found through pattern matching will be automatically hidden. To show passwords in your logs, use
    54  
    55  ```go
    56  util.LogPasswords = true
    57  ```
    58  
    59  It is also possible to skip the output of the some tags (such as the result of `/versions` request,) which are quite large using 
    60  
    61  ```go
    62  util.SetSkipTags("SupportedVersions,ovf:License")
    63  ```
    64  
    65  For an even more dedicated log, you can define from which function names you want the logs, using
    66  
    67  ```go
    68  util.SetApiLogFunctions("FindVAppByName,GetAdminOrgByName")
    69  ```
    70  
    71  ## Custom logger
    72  
    73  If the configuration options are not enough for your needs, you can supply your own logger.
    74  
    75  ```go
    76  util.SetCustomLogger(mylogger)
    77  ```
    78  
    79  ## Environment variables
    80  
    81  The logging behavior can be changed without coding. There are a few environment variables that are checked when the library is used:
    82  
    83  Variable                    | Corresponding environment var 
    84  --------------------------- | :-------------------------------
    85  `EnableLogging`             | `GOVCD_LOG`
    86  `ApiLogFileName`            | `GOVCD_LOG_FILE`
    87  `LogPasswords`              | `GOVCD_LOG_PASSWORDS`
    88  `LogOnScreen`               | `GOVCD_LOG_ON_SCREEN`
    89  `LogHttpRequest`            | `GOVCD_LOG_SKIP_HTTP_REQ`
    90  `LogHttpResponse`           | `GOVCD_LOG_SKIP_HTTP_RESP`
    91  `SetSkipTags`               | `GOVCD_LOG_SKIP_TAGS`
    92  `SetApiLogFunctions`        | `GOVCD_LOG_INCLUDE_FUNCTIONS`
    93  `OverwriteLog`              | `GOVCD_LOG_OVERWRITE`