本文整理匯總了Golang中github.com/fluffle/golog/logging.Warn函數的典型用法代碼示例。如果您正苦於以下問題:Golang Warn函數的具體用法?Golang Warn怎麽用?Golang Warn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Warn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetRand
// TODO(fluffle): thisisn't quite PseudoRand but still ...
func (uc *Collection) GetRand(regex string) *Url {
lookup := bson.M{}
if regex != "" {
// Perform a regex lookup if we have one
lookup["url"] = bson.M{"$regex": regex, "$options": "i"}
}
query := uc.Find(lookup)
count, err := query.Count()
if err != nil {
logging.Warn("Count for URL lookup '%s' failed: %s", regex, err)
return nil
}
if count == 0 {
return nil
}
var res Url
if count > 1 {
query.Skip(rand.Intn(count))
}
if err = query.One(&res); err != nil {
logging.Warn("Fetch for URL lookup '%s' failed: %s", regex, err)
return nil
}
return &res
}
示例2: DelNick
// Removes a Nick from being tracked.
func (st *stateTracker) DelNick(n string) {
if nk, ok := st.nicks[n]; ok {
if nk != st.me {
st.delNick(nk)
} else {
logging.Warn("Tracker.DelNick(): won't delete myself.")
}
} else {
logging.Warn("Tracker.DelNick(): %s not tracked.", n)
}
}
示例3: GetPseudoRand
// TODO(fluffle): reduce duplication with lib/factoids?
func (qc *Collection) GetPseudoRand(regex string) *Quote {
lookup := bson.M{}
if regex != "" {
// Only perform a regex lookup if there's a regex to match against,
// otherwise this just fetches a quote at pseudo-random.
lookup["quote"] = bson.M{"$regex": regex, "$options": "i"}
}
ids, ok := qc.seen[regex]
if ok && len(ids) > 0 {
logging.Debug("Looked for quotes matching '%s' before, %d stored id's",
regex, len(ids))
lookup["_id"] = bson.M{"$nin": ids}
}
query := qc.Find(lookup)
count, err := query.Count()
if err != nil {
logging.Warn("Count for quote lookup '%s' failed: %s", regex, err)
return nil
}
if count == 0 {
if ok {
// Looked for this regex before, but nothing matches now
delete(qc.seen, regex)
}
return nil
}
var res Quote
if count > 1 {
query = query.Skip(rand.Intn(count))
}
if err = query.One(&res); err != nil {
logging.Warn("Fetch for quote lookup '%s' failed: %s", regex, err)
return nil
}
if count != 1 {
if !ok {
// only store seen for regex that match more than one quote
logging.Debug("Creating seen data for regex '%s'.", regex)
qc.seen[regex] = make([]bson.ObjectId, 0, count)
}
logging.Debug("Storing id %v for regex '%s'.", res.Id, regex)
qc.seen[regex] = append(qc.seen[regex], res.Id)
} else if ok {
// if the count of results is 1 and we're storing seen data for regex
// then we've exhausted the possible results and should wipe it
logging.Debug("Zeroing seen data for regex '%s'.", regex)
delete(qc.seen, regex)
}
return &res
}
示例4: Dissociate
// Dissociates an already known nick from an already known channel.
// Does some tidying up to stop tracking nicks we're no longer on
// any common channels with, and channels we're no longer on.
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
if ch == nil || nk == nil {
logging.Error("Tracker.Dissociate(): passed nil values :-(")
} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
// As we can implicitly delete both nicks and channels from being
// tracked by dissociating one from the other, we should verify that
// we're not being passed an old Nick or Channel.
logging.Error("Tracker.Dissociate(): channel %s not found in "+
"(or differs from) internal state.", ch.Name)
} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
logging.Error("Tracker.Dissociate(): nick %s not found in "+
"(or differs from) internal state.", nk.Nick)
} else if _, ok := nk.IsOn(ch); !ok {
logging.Warn("Tracker.Dissociate(): %s not on %s.",
nk.Nick, ch.Name)
} else if nk == st.me {
// I'm leaving the channel for some reason, so it won't be tracked.
st.delChannel(ch)
} else {
// Remove the nick from the channel and the channel from the nick.
ch.delNick(nk)
nk.delChannel(ch)
if len(nk.chans) == 0 {
// We're no longer in any channels with this nick.
st.delNick(nk)
}
}
}
示例5: Associate
// Associates an already known nick with an already known channel.
func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
if ch == nil || nk == nil {
logging.Error("Tracker.Associate(): passed nil values :-(")
return nil
} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
// As we can implicitly delete both nicks and channels from being
// tracked by dissociating one from the other, we should verify that
// we're not being passed an old Nick or Channel.
logging.Error("Tracker.Associate(): channel %s not found in "+
"(or differs from) internal state.", ch.Name)
return nil
} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
logging.Error("Tracker.Associate(): nick %s not found in "+
"(or differs from) internal state.", nk.Nick)
return nil
} else if _, ok := nk.IsOn(ch); ok {
logging.Warn("Tracker.Associate(): %s already on %s.",
nk.Nick, ch.Name)
return nil
}
cp := new(ChanPrivs)
ch.addNick(nk, cp)
nk.addChannel(ch, cp)
return cp
}
示例6: DelChannel
// Removes a Channel from being tracked.
func (st *stateTracker) DelChannel(c string) {
if ch, ok := st.chans[c]; ok {
st.delChannel(ch)
} else {
logging.Warn("Tracker.DelChannel(): %s not tracked.", c)
}
}
示例7: InfoMR
func (fc *Collection) InfoMR(key string) *FactoidInfo {
mr := &mgo.MapReduce{
Map: `function() { emit("count", {
accessed: this.accessed.count,
modified: this.modified.count,
created: this.created.count,
})}`,
Reduce: `function(k,l) {
var sum = { accessed: 0, modified: 0, created: 0 };
for each (var v in l) {
sum.accessed += v.accessed;
sum.modified += v.modified;
sum.created += v.created;
}
return sum;
}`,
}
var res []struct {
Id int `bson:"_id"`
Value FactoidInfo
}
info, err := fc.Find(lookup(key)).MapReduce(mr, &res)
if err != nil || len(res) == 0 {
logging.Warn("Info MR for '%s' failed: %v", key, err)
return nil
} else {
logging.Debug("Info MR mapped %d, emitted %d, produced %d in %d ms.",
info.InputCount, info.EmitCount, info.OutputCount, info.Time/1e6)
}
return &res[0].Value
}
示例8: h_JOIN
// Handle JOINs to channels to maintain state
func (conn *Conn) h_JOIN(line *Line) {
ch := conn.ST.GetChannel(line.Args[0])
nk := conn.ST.GetNick(line.Nick)
if ch == nil {
// first we've seen of this channel, so should be us joining it
// NOTE this will also take care of nk == nil && ch == nil
if nk != conn.Me {
logging.Warn("irc.JOIN(): JOIN to unknown channel %s received "+
"from (non-me) nick %s", line.Args[0], line.Nick)
return
}
ch = conn.ST.NewChannel(line.Args[0])
// since we don't know much about this channel, ask server for info
// we get the channel users automatically in 353 and the channel
// topic in 332 on join, so we just need to get the modes
conn.Mode(ch.Name)
// sending a WHO for the channel is MUCH more efficient than
// triggering a WHOIS on every nick from the 353 handler
conn.Who(ch.Name)
}
if nk == nil {
// this is the first we've seen of this nick
nk = conn.ST.NewNick(line.Nick)
nk.Ident = line.Ident
nk.Host = line.Host
// since we don't know much about this nick, ask server for info
conn.Who(nk.Nick)
}
// this takes care of both nick and channel linking \o/
conn.ST.Associate(ch, nk)
}
示例9: _console_log
func _console_log(args ...interface{}) interface{} {
for _, arg := range args {
log.Warn("> %s", arg)
}
return ""
}
示例10: NewChannel
// Creates a new Channel, initialises it, and stores it so it
// can be properly tracked for state management purposes.
func (st *stateTracker) NewChannel(c string) *Channel {
if _, ok := st.chans[c]; ok {
logging.Warn("Tracker.NewChannel(): %s already tracked.", c)
return nil
}
st.chans[c] = NewChannel(c)
return st.chans[c]
}
示例11: NewNick
// Creates a new Nick, initialises it, and stores it so it
// can be properly tracked for state management purposes.
func (st *stateTracker) NewNick(n string) *Nick {
if _, ok := st.nicks[n]; ok {
logging.Warn("Tracker.NewNick(): %s already tracked.", n)
return nil
}
st.nicks[n] = NewNick(n)
return st.nicks[n]
}
示例12: TopTen
func (sc *Collection) TopTen(ch string) []Nick {
var res []Nick
q := sc.Find(bson.M{"action": "LINES", "chan": ch}).Sort("-lines").Limit(10)
if err := q.All(&res); err != nil {
logging.Warn("TopTen Find error: %v", err)
}
return res
}
示例13: h_671
// Handle 671 whois reply (nick connected via SSL)
func (conn *Conn) h_671(line *Line) {
if nk := conn.ST.GetNick(line.Args[1]); nk != nil {
nk.Modes.SSL = true
} else {
logging.Warn("irc.671(): received WHOIS SSL info for unknown nick %s",
line.Args[1])
}
}
示例14: h_TOPIC
// Handle TOPIC changes for channels
func (conn *Conn) h_TOPIC(line *Line) {
if ch := conn.ST.GetChannel(line.Args[0]); ch != nil {
ch.Topic = line.Args[1]
} else {
logging.Warn("irc.TOPIC(): topic change on unknown channel %s",
line.Args[0])
}
}
示例15: h_332
// Handle 332 topic reply on join to channel
func (conn *Conn) h_332(line *Line) {
if ch := conn.ST.GetChannel(line.Args[1]); ch != nil {
ch.Topic = line.Args[2]
} else {
logging.Warn("irc.332(): received TOPIC value for unknown channel %s",
line.Args[1])
}
}