本文整理匯總了Golang中github.com/dzch/go-utils/logger.Warning函數的典型用法代碼示例。如果您正苦於以下問題:Golang Warning函數的具體用法?Golang Warning怎麽用?Golang Warning使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Warning函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: transData
func (hp *HttpProtocol) transData(server string, transData *TransData) (err error) {
/* compose req */
uri := hp.regTopic.ReplaceAllString(hp.uri, transData.topic)
uri = hp.regMethod.ReplaceAllString(uri, transData.method)
uri = hp.regPartition.ReplaceAllString(uri, strconv.FormatInt(int64(transData.partition), 10))
uri = hp.regTransid.ReplaceAllString(uri, strconv.FormatInt(transData.transid, 10))
url := fmt.Sprintf("http://%s%s", server, uri)
req, err := http.NewRequest("POST", url, bytes.NewReader(transData.data))
if err != nil {
logger.Warning("module [%s]: fail to transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, err=%s", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, err.Error())
return err
}
/* add header */
req.Header = hp.header
req.Host = hp.reqHeaderHost
/* Post */
res, err := hp.client.Do(req)
if err != nil {
logger.Warning("module [%s]: fail to transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, err=%s", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, err.Error())
return err
}
defer res.Body.Close()
/* check res: 200 不重試;其他,重試 */
if res.StatusCode == http.StatusOK {
logger.Notice("module [%s]: success transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, datalen=%d, http_status_code=%d", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, len(transData.data), res.StatusCode)
return nil
} else {
logger.Warning("module [%s]: fail to transData: url=%s, topic=%s, partition=%d, transid=%d, method=%s, http_status_code=%d", hp.moduleName, url, transData.topic, transData.partition, transData.transid, transData.method, res.StatusCode)
return errors.New("fail to trans")
}
return nil
}
示例2: updateBrokerListAndWatch
func (z *Zookeeper) updateBrokerListAndWatch() {
for {
children, _, eventChan, err := z.zkConn.ChildrenW(fmt.Sprintf("%s/brokers/ids", z.cc.chroot))
if err != nil {
err = errors.New(fmt.Sprintf("fail to zk.ChildrenW: %s", err.Error()))
logger.Fatal(err.Error())
z.fatalErrorChan <- err
return
}
if len(children) == 0 {
logger.Warning("no broker found")
} else {
logger.Debug("using child: %s", children[0])
val, _, err := z.zkConn.Get(fmt.Sprintf("%s/brokers/ids/%s", z.cc.chroot, children[0]))
var brokerIdVal BrokerIdVal
err = json.Unmarshal(val, &brokerIdVal)
if err != nil {
logger.Warning("fail to json.Unmarshal for broker id %s: %s", children[0], err.Error())
}
logger.Debug("broker id %s: host [%s] port [%d]", children[0], brokerIdVal.Host, brokerIdVal.Port)
z.brokerIdValChan <- &brokerIdVal
}
<-eventChan
}
}
示例3: ServeHTTP
func (h *GetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
qv := r.URL.Query()
id, partition, offset, err := h.bs.km.parseKey(qv.Get("key"))
if err != nil {
logger.Warning("fail to parseKey: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusBadRequest)
return
}
val, err := h.getData(id, partition, offset)
if err != nil {
logger.Warning("fail to getData: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
_, err = w.Write(val)
if err != nil {
logger.Warning("fail to write response: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
endTime := time.Now()
costTimeUS := endTime.Sub(startTime) / time.Microsecond
logger.Notice("success process get: %s, cost_us=%d, datalen=%d", r.URL.String(), costTimeUS, len(val))
return
}
示例4: ServeHTTP
func (h *StoreHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
/* check query */
if r.ContentLength <= 0 {
logger.Warning("invalid query, need post data: %s", r.URL.String())
w.WriteHeader(http.StatusBadRequest)
return
}
// qv := r.URL.Query()
sr := h.getStoreReq()
defer h.putStoreReq(sr)
nr, err := sr.reqBuffer.ReadFrom(r.Body)
if int64(nr) != r.ContentLength || err != nil {
logger.Warning("fail to read body: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
err = h.parseReq(sr)
if err != nil {
logger.Warning("invalid query, parseReq failed : %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusBadRequest)
return
}
err = h.bs.store.addNewData(sr)
if err != nil {
logger.Warning("fail to write response: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
endTime := time.Now()
costTimeUS := endTime.Sub(startTime) / time.Microsecond
logger.Notice("success process store: %s, id=%d, cost_us=%d", r.URL.String(), sr.id, costTimeUS)
return
}
示例5: updateBrokerOffset
func (b *Broker) updateBrokerOffset() {
if b.client == nil || b.client.Closed() {
logger.Notice("broker.client not ready yet")
return
}
topics, err := b.client.Topics()
if err != nil {
logger.Warning("fail to b.client.Topics(): %s", err.Error())
return
}
for _, topic := range topics {
partitions, err := b.client.Partitions(topic)
if err != nil {
logger.Warning("fail to b.client.Partitions(): %s", err.Error())
continue
}
for _, partition := range partitions {
offset, err := b.client.GetOffset(topic, partition, sarama.OffsetNewest)
if err != nil {
logger.Warning("fail to b.client.GetOffset topic=%s, partition=%d, err=%s", topic, partition, err.Error())
continue
}
// TODO: use pool
b.brokerOffsetChan <- &BrokerOffset{
topic: topic,
partition: partition,
offset: offset,
}
logger.Debug("offset: topic=%s, partition=%d, offset=%d", topic, partition, offset)
}
}
}
示例6: ServeHTTP
func (ch *CmHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
/* check query */
if r.ContentLength <= 0 {
logger.Warning("invalid query, need post data: %s", r.URL.String())
w.WriteHeader(http.StatusBadRequest)
return
}
qv := r.URL.Query()
post := make([]byte, r.ContentLength)
nr, err := io.ReadFull(r.Body, post)
if int64(nr) != r.ContentLength {
logger.Warning("fail to read body: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
/* compose CmData */
cmData := ch.cdp.fetch()
defer ch.cdp.put(cmData)
switch qv.Get("acks") {
case "0":
cmData.requiredAcks = sarama.NoResponse
case "1":
cmData.requiredAcks = sarama.WaitForLocal
case "-1":
cmData.requiredAcks = sarama.WaitForAll
default:
cmData.requiredAcks = sarama.WaitForLocal
}
cmData.topic = qv.Get("topic")
cmData.key = qv.Get("key")
cmData.data = post
/* commit */
ch.kp.producer.produce(cmData)
/* wait res */
<-cmData.cmDoneChan
if cmData.err != nil {
logger.Warning("fail to commit req: %s, error: %s", r.URL.String(), (*(cmData.err)).Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
endTime := time.Now()
costTimeUS := endTime.Sub(startTime) / time.Microsecond
// TODO
logger.Notice("success process commit: %s, cost_us=%d, datalen=%d, offset=%d, partition=%d", r.URL.String(), costTimeUS, nr, cmData.offset, cmData.partition)
w.WriteHeader(http.StatusOK)
return
}
示例7: computeTransDelay
func (c *Cluster) computeTransDelay(transDelayChan chan TransDelay) {
resMap := make(map[string]map[string]int64)
for cg, tm := range c.cs.transfer.transferOffset {
for topic, pm := range tm {
dpm, ok := resMap[cg]
if !ok {
dpm = make(map[string]int64)
resMap[cg] = dpm
}
for partition, tor := range pm {
bor, ok := c.cs.broker.brokerOffset[topic][partition]
if !ok {
logger.Warning("no broker offset record found: topic=%s, partition=%d", topic, partition)
dpm[strconv.FormatInt(int64(partition), 10)] = 0
continue
}
bo := c.computeBrokerOffsetAtTime(tor.last.timestamp, bor)
delay := bo - tor.last.offset
if delay < 0 {
delay = 0
}
dpm[strconv.FormatInt(int64(partition), 10)] = delay
}
}
}
transDelayChan <- TransDelay(resMap)
}
示例8: processAckData
/* do not change state in this func */
func (td *TransDi) processAckData(ackData *AckData) {
transid := ackData.transid
workerId := ackData.workerId
logger.Debug("process ack: transid=%d, workerId=%d", transid, workerId)
/* narrow window */
msg := td.transWindow.ackOne(transid)
if msg != nil && msg.Offset > td.ackedMinTransid {
td.ackedMinTransid = msg.Offset
err := td.cg.CommitUpto(msg)
if err != nil {
// TODO: optimized
logger.Warning("fail to consumergroup.CommitUpto(): %s", err.Error())
td.fatalErrorChan <- err
return
}
logger.Debug("consumergroup.CommitUpTo %d", msg.Offset)
}
logger.Debug("transWindow size: %d", td.transWindow.window.Len())
/* move worker */
worker := td.transWorkers[workerId]
worker.inWork = false
err := worker.workIfNeed()
if err != nil {
logger.Fatal("fail to let worker to work: %s", err.Error())
td.fatalErrorChan <- err
return
}
}
示例9: updateCgAndWatch
func (z *Zookeeper) updateCgAndWatch(cg string) {
path := fmt.Sprintf("%s/consumers/%s/offsets", z.cc.chroot, cg)
for {
children, _, eventChan, err := z.zkConn.ChildrenW(path)
if err == zk.ErrNoNode {
_, _, eventChan, err = z.zkConn.ExistsW(path)
if err != nil {
err = errors.New(fmt.Sprintf("fail to zk.ExistsW: path=%s, %s", path, err.Error()))
logger.Fatal(err.Error())
z.fatalErrorChan <- err
return
}
<-eventChan
continue
}
if err != nil {
err = errors.New(fmt.Sprintf("fail to zk.ChildrenW: path=%s, %s", path, err.Error()))
logger.Fatal(err.Error())
z.fatalErrorChan <- err
return
}
if len(children) == 0 {
logger.Warning("no transfer topic found: path=%s", path)
} else {
for _, topic := range children {
go z.updateTopicAndWatch(cg, topic)
}
}
event := <-eventChan
// let root watcher to re-init
if event.Type == zk.EventNotWatching {
return
}
}
}
示例10: Run
func (d *Deleter) Run() (err error) {
err = d.httpServer.ListenAndServe()
if err != nil {
logger.Warning("fail to httpServer.ListenAndServe: %s", err.Error())
return
}
logger.Notice("httpServer.ListenAndServe end")
return nil
}
示例11: fetch
func (pmp *PMsgPool) fetch() *PMsgPoolEle {
if pmp.poolFreeSize <= 0 {
logger.Warning("Producer Message Pool is too small")
return pmp.newPMsgPoolEle()
}
r := pmp.root.r.Unlink(1)
pmp.poolFreeSize--
return r.Value.(*PMsgPoolEle)
}
示例12: fetch
func (cdp *CmDataPool) fetch() *CmData {
var cd *CmData
select {
case cd = <-cdp.pool:
default:
logger.Warning("cm_data_pool is not big enough")
cd = cdp.newCmData()
}
return cd
}
示例13: run
func (zk *ZK) run() {
for {
err := zk.updateOffsets()
if err != nil {
logger.Warning("fail to zk.updateOffsets: %s", err.Error())
time.Sleep(zk.config.zkFailRetryInterval)
}
time.Sleep(zk.config.zkUpdateInterval)
}
}
示例14: initProtocol
func (worker *TransWorker) initProtocol() (err error) {
name, ok := worker.protocolConfig["name"]
if !ok {
err = errors.New(fmt.Sprintf("protocol.name not found in module conf file, module [%s]", worker.moduleName))
logger.Warning("%s", err.Error())
return
}
worker.protocolName = name.(string)
switch worker.protocolName {
case "http":
err = worker.initHttpProtocol()
default:
err = errors.New(fmt.Sprintf("unknown protocol: %s", worker.protocolName))
}
if err != nil {
logger.Warning("fail to init protocol for module [%s]: %s", worker.moduleName, err.Error())
return
}
return nil
}
示例15: handleCm
func (httpServer *HttpServer) handleCm(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
/* check query */
if r.ContentLength <= 0 {
logger.Warning("invalid query, need post data: %s", r.URL.String())
w.WriteHeader(http.StatusBadRequest)
return
}
qv := r.URL.Query()
post := make([]byte, r.ContentLength)
nr, err := io.ReadFull(r.Body, post)
if int64(nr) != r.ContentLength {
logger.Warning("fail to read body: %s, %s", r.URL.String(), err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
/* compose CmData */
cmData := httpServer.cdp.fetch()
defer httpServer.cdp.put(cmData)
cmData.topic = qv.Get("topic")
cmData.key = qv.Get("key")
cmData.data = post
/* commit */
httpServer.cmDataChan <- cmData
/* wait res */
<-cmData.cmDoneChan
if cmData.err != nil {
logger.Warning("fail to commit req: %s, error: %s", r.URL.String(), (*(cmData.err)).Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
endTime := time.Now()
costTimeUS := endTime.Sub(startTime) / time.Microsecond
// TODO
logger.Notice("success process commit: %s, cost_us=%d, datalen=%d, offset=%d, partition=%d", r.URL.String(), costTimeUS, nr, cmData.offset, cmData.partition)
w.WriteHeader(http.StatusOK)
return
}