日志级别
This commit is contained in:
parent
98742b2ce2
commit
c868d2650a
13
conf/wide.go
13
conf/wide.go
|
@ -3,14 +3,15 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
_ "github.com/b3log/wide/i18n"
|
|
||||||
"github.com/b3log/wide/util"
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
_ "github.com/b3log/wide/i18n"
|
||||||
|
"github.com/b3log/wide/util"
|
||||||
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -87,7 +88,7 @@ func Load() {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("IP [%s]", ip)
|
glog.V(3).Infof("IP [%s]", ip)
|
||||||
Wide.Server = strings.Replace(Wide.Server, "{IP}", ip, 1)
|
Wide.Server = strings.Replace(Wide.Server, "{IP}", ip, 1)
|
||||||
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", ip, 1)
|
Wide.StaticServer = strings.Replace(Wide.StaticServer, "{IP}", ip, 1)
|
||||||
Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", ip, 1)
|
Wide.EditorChannel = strings.Replace(Wide.EditorChannel, "{IP}", ip, 1)
|
||||||
|
@ -98,10 +99,10 @@ func Load() {
|
||||||
file, _ := exec.LookPath(os.Args[0])
|
file, _ := exec.LookPath(os.Args[0])
|
||||||
pwd, _ := filepath.Abs(file)
|
pwd, _ := filepath.Abs(file)
|
||||||
pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))]
|
pwd = pwd[:strings.LastIndex(pwd, string(os.PathSeparator))]
|
||||||
glog.Infof("pwd [%s]", pwd)
|
glog.V(3).Infof("pwd [%s]", pwd)
|
||||||
|
|
||||||
Wide.Workspace = strings.Replace(Wide.Workspace, "{pwd}", pwd, 1)
|
Wide.Workspace = strings.Replace(Wide.Workspace, "{pwd}", pwd, 1)
|
||||||
Wide.UserWorkspaces = strings.Replace(Wide.UserWorkspaces, "{pwd}", pwd, 1)
|
Wide.UserWorkspaces = strings.Replace(Wide.UserWorkspaces, "{pwd}", pwd, 1)
|
||||||
|
|
||||||
glog.Info("Conf: \n" + string(bytes))
|
glog.V(3).Info("Conf: \n" + string(bytes))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,11 @@ package i18n
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/golang/glog"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type locale struct {
|
type locale struct {
|
||||||
|
@ -33,7 +34,7 @@ func Load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Locales["zh_CN"] = zhCN
|
Locales["zh_CN"] = zhCN
|
||||||
glog.Info("Loaded [zh_CN] locale configuration")
|
glog.V(5).Info("Loaded [zh_CN] locale configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLangs(r *http.Request) map[string]interface{} {
|
func GetLangs(r *http.Request) map[string]interface{} {
|
||||||
|
|
3
main.go
3
main.go
|
@ -21,6 +21,7 @@ import (
|
||||||
// Wide 中唯一一个 init 函数.
|
// Wide 中唯一一个 init 函数.
|
||||||
func init() {
|
func init() {
|
||||||
flag.Set("logtostderr", "true")
|
flag.Set("logtostderr", "true")
|
||||||
|
flag.Set("v", "1")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
@ -105,7 +106,7 @@ func main() {
|
||||||
// 文档
|
// 文档
|
||||||
http.Handle("/doc/", http.StripPrefix("/doc/", http.FileServer(http.Dir("doc"))))
|
http.Handle("/doc/", http.StripPrefix("/doc/", http.FileServer(http.Dir("doc"))))
|
||||||
|
|
||||||
glog.Infof("Wide is running [%s]", conf.Wide.Server)
|
glog.V(0).Infof("Wide is running [%s]", conf.Wide.Server)
|
||||||
|
|
||||||
err := http.ListenAndServe(conf.Wide.Server, nil)
|
err := http.ListenAndServe(conf.Wide.Server, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,11 +2,6 @@ package output
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/b3log/wide/conf"
|
|
||||||
"github.com/b3log/wide/user"
|
|
||||||
"github.com/b3log/wide/util"
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -14,6 +9,12 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/b3log/wide/conf"
|
||||||
|
"github.com/b3log/wide/user"
|
||||||
|
"github.com/b3log/wide/util"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
var outputWS = map[string]*websocket.Conn{}
|
var outputWS = map[string]*websocket.Conn{}
|
||||||
|
@ -27,7 +28,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-output"}
|
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-output"}
|
||||||
outputWS[sid].WriteJSON(&ret)
|
outputWS[sid].WriteJSON(&ret)
|
||||||
|
|
||||||
glog.Infof("Open a new [Output] with session [%s], %d", sid, len(outputWS))
|
glog.V(4).Infof("Open a new [Output] with session [%s], %d", sid, len(outputWS))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunHandler(w http.ResponseWriter, r *http.Request) {
|
func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -77,14 +78,14 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
channelRet := map[string]interface{}{}
|
channelRet := map[string]interface{}{}
|
||||||
|
|
||||||
go func(runningId int) {
|
go func(runningId int) {
|
||||||
glog.Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath)
|
glog.V(3).Infof("Session [%s] is running [id=%d, file=%s]", sid, runningId, filePath)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
count, err := reader.Read(buf)
|
count, err := reader.Read(buf)
|
||||||
|
|
||||||
if nil != err || 0 == count {
|
if nil != err || 0 == count {
|
||||||
glog.Infof("Session [%s] 's running [id=%d, file=%s] has done", sid, runningId, filePath)
|
glog.V(3).Infof("Session [%s] 's running [id=%d, file=%s] has done", sid, runningId, filePath)
|
||||||
|
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
@ -157,7 +158,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
setCmdEnv(cmd, username)
|
setCmdEnv(cmd, username)
|
||||||
|
|
||||||
glog.Infof("go build -o %s %s", executable, filePath)
|
glog.V(5).Infof("go build -o %s %s", executable, filePath)
|
||||||
|
|
||||||
executable = curDir + string(os.PathSeparator) + executable
|
executable = curDir + string(os.PathSeparator) + executable
|
||||||
|
|
||||||
|
@ -192,7 +193,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd.Start()
|
cmd.Start()
|
||||||
|
|
||||||
go func(runningId int) {
|
go func(runningId int) {
|
||||||
glog.Infof("Session [%s] is building [id=%d, file=%s]", sid, runningId, filePath)
|
glog.V(3).Infof("Session [%s] is building [id=%d, file=%s]", sid, runningId, filePath)
|
||||||
|
|
||||||
// 一次性读取
|
// 一次性读取
|
||||||
buf := make([]byte, 1024*8)
|
buf := make([]byte, 1024*8)
|
||||||
|
@ -220,7 +221,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
channelRet["executable"] = executable
|
channelRet["executable"] = executable
|
||||||
|
|
||||||
if nil != outputWS[sid] {
|
if nil != outputWS[sid] {
|
||||||
glog.Infof("Session [%s] 's build [id=%d, file=%s] has done", sid, runningId, filePath)
|
glog.V(3).Infof("Session [%s] 's build [id=%d, file=%s] has done", sid, runningId, filePath)
|
||||||
|
|
||||||
err := outputWS[sid].WriteJSON(&channelRet)
|
err := outputWS[sid].WriteJSON(&channelRet)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
@ -282,14 +283,14 @@ func GoGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
channelRet := map[string]interface{}{}
|
channelRet := map[string]interface{}{}
|
||||||
|
|
||||||
go func(runningId int) {
|
go func(runningId int) {
|
||||||
glog.Infof("Session [%s] is running [go get] [runningId=%d]", sid, runningId)
|
glog.V(3).Infof("Session [%s] is running [go get] [runningId=%d]", sid, runningId)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
count, err := reader.Read(buf)
|
count, err := reader.Read(buf)
|
||||||
|
|
||||||
if nil != err || 0 == count {
|
if nil != err || 0 == count {
|
||||||
glog.Infof("Session [%s] 's running [go get] [runningId=%d] has done", sid, runningId)
|
glog.V(3).Infof("Session [%s] 's running [go get] [runningId=%d] has done", sid, runningId)
|
||||||
|
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue