本文整理汇总了Golang中log.Print函数的典型用法代码示例。如果您正苦于以下问题:Golang Print函数的具体用法?Golang Print怎么用?Golang Print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Print函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
// Redirect log output to file.
_, prog := filepath.Split(os.Args[0])
log_path := filepath.Join(os.TempDir(), prog+".INFO")
w, err := os.OpenFile(log_path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err == nil {
log.Print("Setting log output to ", log_path)
log.SetOutput(w)
log.Print("Logfile created")
} else {
log.Print("Failed to redirect output: ", err)
}
serverURL := ServeAsync()
block := !*window
if *window {
if err := platform.WebviewWindow(serverURL); err != nil {
log.Print(err)
block = true
}
}
// If we're not starting a window (or it failed), block forever instead.
if block {
select {}
}
log.Println("Main done, terminating.")
}
示例2: handleWS
func (app *App) handleWS(w http.ResponseWriter, r *http.Request) {
log.Printf("New client connected: %s", r.RemoteAddr)
if r.Method != "GET" {
http.Error(w, "Method not allowed", 405)
return
}
conn, err := app.upgrader.Upgrade(w, r, nil)
if err != nil {
log.Print("Failed to upgrade connection")
return
}
cmd := exec.Command(app.options.Command[0], app.options.Command[1:]...)
ptyIo, err := pty.Start(cmd)
if err != nil {
log.Print("Failed to execute command")
return
}
log.Printf("Command is running for client %s with PID %d", r.RemoteAddr, cmd.Process.Pid)
context := &clientContext{
app: app,
request: r,
connection: conn,
command: cmd,
pty: ptyIo,
}
context.goHandleClient()
}
示例3: main
func main() {
var te *walk.TextEdit
if _, err := (MainWindow{
Title: "Walk Clipboard Example",
MinSize: Size{300, 200},
Layout: VBox{},
Children: []Widget{
PushButton{
Text: "Copy",
OnClicked: func() {
if err := walk.Clipboard().SetText(te.Text()); err != nil {
log.Print("Copy: ", err)
}
},
},
PushButton{
Text: "Paste",
OnClicked: func() {
if text, err := walk.Clipboard().Text(); err != nil {
log.Print("Paste: ", err)
} else {
te.SetText(text)
}
},
},
TextEdit{
AssignTo: &te,
},
},
}).Run(); err != nil {
log.Fatal(err)
}
}
示例4: GetTpCdrStats
func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) {
csvReader, fp, err := csvs.readerFunc(csvs.cdrStatsFn, csvs.sep, getColumnCount(TpCdrstat{}))
if err != nil {
log.Print("Could not load cdr stats file: ", err)
// allow writing of the other values
return nil, nil
}
if fp != nil {
defer fp.Close()
}
var tpCdrStats []TpCdrstat
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
if err != nil {
log.Print("bad line in cdr stats csv: ", err)
return nil, err
}
if tpCdrStat, err := csvLoad(TpCdrstat{}, record); err != nil {
log.Print("error loading cdr stat: ", err)
return nil, err
} else {
cs := tpCdrStat.(TpCdrstat)
cs.Tpid = tpid
tpCdrStats = append(tpCdrStats, cs)
}
}
return tpCdrStats, nil
}
示例5: GetTpTimings
func (csvs *CSVStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) {
csvReader, fp, err := csvs.readerFunc(csvs.timingsFn, csvs.sep, getColumnCount(TpTiming{}))
if err != nil {
log.Print("Could not load timings file: ", err)
// allow writing of the other values
return nil, nil
}
if fp != nil {
defer fp.Close()
}
var tpTimings []TpTiming
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
if err != nil {
log.Print("bad line in timings csv: ", err)
return nil, err
}
if tpTiming, err := csvLoad(TpTiming{}, record); err != nil {
log.Print("error loading timing: ", err)
return nil, err
} else {
tm := tpTiming.(TpTiming)
tm.Tpid = tpid
tpTimings = append(tpTimings, tm)
}
}
return tpTimings, nil
}
示例6: GetTpLCRs
func (csvs *CSVStorage) GetTpLCRs(filter *TpLcrRule) ([]TpLcrRule, error) {
csvReader, fp, err := csvs.readerFunc(csvs.lcrFn, csvs.sep, getColumnCount(TpLcrRule{}))
if err != nil {
log.Print("Could not load LCR rules file: ", err)
// allow writing of the other values
return nil, nil
}
if fp != nil {
defer fp.Close()
}
var tpLCRs []TpLcrRule
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
if tpRate, err := csvLoad(TpLcrRule{}, record); err != nil {
if err != nil {
log.Print("bad line in lcr rules csv: ", err)
return nil, err
}
return nil, err
} else {
lcr := tpRate.(TpLcrRule)
if filter != nil {
lcr.Tpid = filter.Tpid
}
tpLCRs = append(tpLCRs, lcr)
}
}
return tpLCRs, nil
}
示例7: GetTpAccountActions
func (csvs *CSVStorage) GetTpAccountActions(filter *TpAccountAction) ([]TpAccountAction, error) {
csvReader, fp, err := csvs.readerFunc(csvs.accountactionsFn, csvs.sep, getColumnCount(TpAccountAction{}))
if err != nil {
log.Print("Could not load account actions file: ", err)
// allow writing of the other values
return nil, nil
}
if fp != nil {
defer fp.Close()
}
var tpAccountActions []TpAccountAction
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
if err != nil {
log.Print("bad line in account actions csv: ", err)
return nil, err
}
if tpAa, err := csvLoad(TpAccountAction{}, record); err != nil {
log.Print("error loading account action: ", err)
return nil, err
} else {
aa := tpAa.(TpAccountAction)
if filter != nil {
aa.Tpid = filter.Tpid
aa.Loadid = filter.Loadid
}
tpAccountActions = append(tpAccountActions, aa)
}
}
return tpAccountActions, nil
}
示例8: handleClientRegister
func handleClientRegister(httpReq *http.Request) (int, string) {
//using authentication struct for now because i haven't added the token yet
var req request.Authentication
decoder := json.NewDecoder(httpReq.Body)
err := decoder.Decode(&req)
if err != nil {
fmt.Println("error decoding register account request (authentication)")
return 500, "Internal Server Error"
}
var username string
var password string
username, password, err = sanitize(req.Username, req.Password)
if err != nil {
log.Print("Error sanitizing authentication request", req.Username, req.Password)
return 400, "Bad Request"
}
uid, err := thordb.RegisterAccount(username, password)
if err != nil {
log.Print(err)
switch err.Error() {
case "thordb: already in use":
return 400, "Bad Request"
default:
return 500, "Internal Server Error"
}
}
log.Print("thordb: registered player (", uid, ")")
return 200, fmt.Sprintf("UserId%s", strconv.Itoa(uid))
}
示例9: handleCreateCharacter
func handleCreateCharacter(httpReq *http.Request) (int, string) {
var req request.CreateCharacter
decoder := json.NewDecoder(httpReq.Body)
err := decoder.Decode(&req)
if err != nil {
log.Print("character create req json decoding error %s", httpReq.Body)
return 400, "Bad Request"
}
character := thordb.NewCharacterData()
character.Name = req.Name
var characterSession *thordb.CharacterSession
characterSession, err = thordb.CreateCharacter(req.AccountToken, character)
if err != nil {
log.Print(err)
switch err.Error() {
case "thordb: already in use":
return 400, "Bad Request"
case "token contains an invalid number of segments":
return 400, "Bad Request"
default:
return 500, "Internal Server Error"
}
}
var jsonBytes []byte
jsonBytes, err = json.Marshal(characterSession.CharacterData)
if err != nil {
log.Print(err)
return 500, "Internal Server Error"
}
log.Printf("thordb: created character %d - %s\ncharacter details:\n%s", characterSession.ID, characterSession.Name, string(jsonBytes))
return 200, characterSession.Token
}
示例10: Close
/**
* Close the connection to the server
*/
func (mysql *MySQL) Close() (err os.Error) {
if mysql.Logging {
log.Print("Close called")
}
// If not connected return
if !mysql.connected {
err = os.NewError("A connection to a MySQL server is required to use this function")
return
}
// Lock mutex and defer unlock
mysql.mutex.Lock()
defer mysql.mutex.Unlock()
// Reset error/sequence vars
mysql.reset()
// Send quit command
err = mysql.command(COM_QUIT, "")
if err != nil {
return
}
if mysql.Logging {
log.Print("[" + fmt.Sprint(mysql.sequence-1) + "] " + "Sent quit command to server")
}
// Close connection
mysql.conn.Close()
mysql.connected = false
if mysql.Logging {
log.Print("Closed connection to server")
}
return
}
示例11: Ping
/**
* Ping server
*/
func (mysql *MySQL) Ping() (err os.Error) {
if mysql.Logging {
log.Print("Ping called")
}
// If not connected return
if !mysql.connected {
err = os.NewError("A connection to a MySQL server is required to use this function")
return
}
// Lock mutex and defer unlock
mysql.mutex.Lock()
defer mysql.mutex.Unlock()
// Reset error/sequence vars
mysql.reset()
// Send command
err = mysql.command(COM_PING)
if err != nil {
return
}
if mysql.Logging {
log.Print("[" + fmt.Sprint(mysql.sequence-1) + "] " + "Sent ping command to server")
}
// Get result packet
err = mysql.getResult()
return
}
示例12: mainHandler
func mainHandler(rw http.ResponseWriter, req *http.Request) {
relPath := req.URL.Path[1:] // serveFile URL paths start with '/'
if strings.Contains(relPath, "..") {
return
}
if strings.HasPrefix(relPath, "gw/") {
path := relPath[3:]
http.Redirect(rw, req, "http://camlistore.org/code/?p=camlistore.git;f="+path+";hb=master", http.StatusFound)
return
}
absPath := filepath.Join(*root, "content", relPath)
fi, err := os.Lstat(absPath)
if err != nil {
log.Print(err)
serveError(rw, req, relPath, err)
return
}
if fi.IsDir() {
relPath += "/index.html"
absPath = filepath.Join(*root, "content", relPath)
fi, err = os.Lstat(absPath)
if err != nil {
log.Print(err)
serveError(rw, req, relPath, err)
return
}
}
switch {
case !fi.IsDir():
serveFile(rw, req, relPath, absPath)
}
}
示例13: handleConnection
func handleConnection(conn *BinaryWriter) {
defer conn.conn.Close()
// log.Print("CONNECT!")
decoder := BIN.NewDecoder(bufio.NewReader(conn.conn))
_, err := decoder.DecodeHello()
if err != nil {
log.Print(err)
return
}
for {
req, err := decoder.DecodeRequest()
if err == io.EOF {
log.Print(err)
break
} else if err != nil {
log.Print(err)
break
}
// log.Printf("GOT REQUEST %s", req)
// //request
controller := conn.serverConfig.Router.Match(req.Method(), req.Uri())
go HandleRequest(req, conn, controller, conn.serverConfig)
}
log.Print("DISCONNECT!")
}
示例14: setupListener
func (me *ServerManager) setupListener(port int) {
portStr := strconv.Itoa(port)
addr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:"+portStr)
if err != nil {
log.Print("Could not resolve port and listen address:", err)
return
}
// listen on port
go func() {
l, err := net.ListenTCP("tcp", addr)
if err != nil {
log.Print("Could not listen for TCP connection:", err)
} else {
for {
conn, err := l.AcceptTCP()
if err != nil {
log.Print("Could not accept TCP connection:", err)
} else {
// connection accepted
// spinup machine
me.Spinup()
// close existing connection, not doing anything with it
conn.Close()
}
}
}
}()
}
示例15: GetTpRatingProfiles
func (csvs *CSVStorage) GetTpRatingProfiles(filter *TpRatingProfile) ([]TpRatingProfile, error) {
csvReader, fp, err := csvs.readerFunc(csvs.ratingprofilesFn, csvs.sep, getColumnCount(TpRatingProfile{}))
if err != nil {
log.Print("Could not load rating profiles file: ", err)
// allow writing of the other values
return nil, nil
}
if fp != nil {
defer fp.Close()
}
var tpRatingProfiles []TpRatingProfile
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
if err != nil {
log.Print("bad line rating profiles csv: ", err)
return nil, err
}
if tpRate, err := csvLoad(TpRatingProfile{}, record); err != nil {
log.Print("error loading rating profile: ", err)
return nil, err
} else {
rpf := tpRate.(TpRatingProfile)
if filter != nil {
rpf.Tpid = filter.Tpid
rpf.Loadid = filter.Loadid
}
tpRatingProfiles = append(tpRatingProfiles, rpf)
}
}
return tpRatingProfiles, nil
}