当前位置: 首页>>代码示例>>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;未经允许,请勿转载。