當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.NewLogger函數代碼示例

本文整理匯總了Golang中github.com/b3log/wide/log.NewLogger函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewLogger函數的具體用法?Golang NewLogger怎麽用?Golang NewLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewLogger函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

// The only one init function in Wide.
func init() {
	confPath := flag.String("conf", "conf/wide.json", "path of wide.json")
	confIP := flag.String("ip", "", "this will overwrite Wide.IP if specified")
	confPort := flag.String("port", "", "this will overwrite Wide.Port if specified")
	confServer := flag.String("server", "", "this will overwrite Wide.Server if specified")
	confLogLevel := flag.String("log_level", "", "this will overwrite Wide.LogLevel if specified")
	confStaticServer := flag.String("static_server", "", "this will overwrite Wide.StaticServer if specified")
	confContext := flag.String("context", "", "this will overwrite Wide.Context if specified")
	confChannel := flag.String("channel", "", "this will overwrite Wide.Channel if specified")
	confStat := flag.Bool("stat", false, "whether report statistics periodically")
	confDocker := flag.Bool("docker", false, "whether run in a docker container")
	confPlayground := flag.String("playground", "", "this will overwrite Wide.Playground if specified")

	flag.Parse()

	log.SetLevel("warn")
	logger = log.NewLogger(os.Stdout)

	wd := util.OS.Pwd()
	if strings.HasPrefix(wd, os.TempDir()) {
		logger.Error("Don't run Wide in OS' temp directory or with `go run`")

		os.Exit(-1)
	}

	i18n.Load()

	event.Load()

	conf.Load(*confPath, *confIP, *confPort, *confServer, *confLogLevel, *confStaticServer, *confContext, *confChannel,
		*confPlayground, *confDocker)

	conf.FixedTimeCheckEnv()

	session.FixedTimeSave()
	session.FixedTimeRelease()

	if *confStat {
		session.FixedTimeReport()
	}

	logger.Debug("host ["+runtime.Version()+", "+runtime.GOOS+"_"+runtime.GOARCH+"], cross-compilation ",
		util.Go.GetCrossPlatforms())
}
開發者ID:toyang,項目名稱:wide,代碼行數:45,代碼來源:main.go

示例2: Load

	StaticServer          string // static resources server scheme, host and port (http://{IP}:{Port})
	LogLevel              string // logging level: trace/debug/info/warn/error
	Channel               string // channel (ws://{IP}:{Port})
	HTTPSessionMaxAge     int    // HTTP session max age (in seciond)
	StaticResourceVersion string // version of static resources
	MaxProcs              int    // Go max procs
	RuntimeMode           string // runtime mode (dev/prod)
	WD                    string // current working direcitory, ${pwd}
	Locale                string // default locale
	Playground            string // playground directory
	AllowRegister         bool   // allow register or not
	Autocomplete          bool   // default autocomplete
}

// Logger.
var logger = log.NewLogger(os.Stdout)

// Wide configurations.
var Wide *conf

// configurations of users.
var Users []*User

// Indicates whether runs via Docker.
var Docker bool

// Load loads the Wide configurations from wide.json and users' configurations from users/{username}.json.
func Load(confPath, confIP, confPort, confServer, confLogLevel, confStaticServer, confContext, confChannel,
	confPlayground string, confDocker bool) {
	// XXX: ugly args list....
開發者ID:nivance,項目名稱:wide,代碼行數:30,代碼來源:wide.go

示例3: GetFileSize

// See the License for the specific language governing permissions and
// limitations under the License.

package util

import (
	"io"
	"os"
	"path/filepath"
	"strings"

	"github.com/b3log/wide/log"
)

// Logger.
var fileLogger = log.NewLogger(os.Stdout)

type myfile struct{}

// File utilities.
var File = myfile{}

// GetFileSize get the length in bytes of file of the specified path.
func (*myfile) GetFileSize(path string) int64 {
	fi, err := os.Stat(path)
	if nil != err {
		return -1
	}

	return fi.Size()
}
開發者ID:29206394,項目名稱:wide,代碼行數:31,代碼來源:file.go

示例4: NewResult

// See the License for the specific language governing permissions and
// limitations under the License.

package util

import (
	"compress/gzip"
	"encoding/json"
	"net/http"
	"os"

	"github.com/b3log/wide/log"
)

// Logger.
var retLogger = log.NewLogger(os.Stdout)

// Result.
type Result struct {
	Succ bool        `json:"succ"` // successful or not
	Code string      `json:"code"` // return code
	Msg  string      `json:"msg"`  // message
	Data interface{} `json:"data"` // data object
}

// NewResult creates a result with Succ=true, Code="0", Msg="", Data=nil.
func NewResult() *Result {
	return &Result{
		Succ: true,
		Code: "0",
		Msg:  "",
開發者ID:toyang,項目名稱:wide,代碼行數:31,代碼來源:ret.go

示例5: loadConf

func loadConf(confIP, confPort, confChannel string) {
	bytes, err := ioutil.ReadFile("conf/coditor.json")
	if nil != err {
		logger.Error(err)

		os.Exit(-1)
	}

	conf = &config{}

	err = json.Unmarshal(bytes, conf)
	if err != nil {
		logger.Error("Parses [coditor.json] error: ", err)

		os.Exit(-1)
	}

	log.SetLevel(conf.LogLevel)

	logger = log.NewLogger(os.Stdout)

	logger.Debug("Conf: \n" + string(bytes))

	// Working Driectory
	conf.WD = util.OS.Pwd()
	logger.Debugf("${pwd} [%s]", conf.WD)

	// IP
	ip, err := util.Net.LocalIP()
	if err != nil {
		logger.Error(err)

		os.Exit(-1)
	}

	logger.Debugf("${ip} [%s]", ip)

	conf.IP = strings.Replace(conf.IP, "${ip}", ip, 1)
	if "" != confIP {
		conf.IP = confIP
	}

	if "" != confPort {
		conf.Port = confPort
	}

	// Server
	conf.Server = strings.Replace(conf.Server, "{IP}", conf.IP, 1)

	// Static Server
	conf.StaticServer = strings.Replace(conf.StaticServer, "{IP}", conf.IP, 1)
	conf.StaticServer = strings.Replace(conf.StaticServer, "{Port}", conf.Port, 1)

	conf.StaticResourceVersion = strings.Replace(conf.StaticResourceVersion, "${time}", strconv.FormatInt(time.Now().UnixNano(), 10), 1)

	// Channel
	conf.Channel = strings.Replace(conf.Channel, "{IP}", conf.IP, 1)
	conf.Channel = strings.Replace(conf.Channel, "{Port}", conf.Port, 1)

	if "" != confChannel {
		conf.Channel = confChannel
	}

	conf.Server = strings.Replace(conf.Server, "{Port}", conf.Port, 1)

}
開發者ID:marswang,項目名稱:coditorx,代碼行數:66,代碼來源:conf.go


注:本文中的github.com/b3log/wide/log.NewLogger函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。