This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
/
logging.go
59 lines (51 loc) · 1.69 KB
/
logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
* Copyright (c) 2020 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package actions
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/eclipse/codewind-installer/pkg/apiroutes"
"github.com/eclipse/codewind-installer/pkg/config"
"github.com/eclipse/codewind-installer/pkg/connections"
"github.com/eclipse/codewind-installer/pkg/utils"
"github.com/urfave/cli"
)
// LogLevels : Optionally set then display the log level information
// for a Codewind PFE container
func LogLevels(c *cli.Context) {
connectionID := strings.TrimSpace(strings.ToLower(c.String("conid")))
newLogLevel := strings.TrimSpace(strings.ToLower(c.Args().Get(0)))
conInfo, conInfoErr := connections.GetConnectionByID(connectionID)
if conInfoErr != nil {
fmt.Println(conInfoErr.Err)
os.Exit(1)
}
conURL, conErr := config.PFEOriginFromConnection(conInfo)
if conErr != nil {
fmt.Println(conErr.Err)
os.Exit(1)
}
if newLogLevel != "" {
err := apiroutes.SetLogLevel(conInfo, conURL, http.DefaultClient, newLogLevel)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
loggingLevels, err := apiroutes.GetLogLevel(conInfo, conURL, http.DefaultClient)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
utils.PrettyPrintJSON(loggingLevels)
}