本文整理汇总了Golang中log/syslog.Writer类的典型用法代码示例。如果您正苦于以下问题:Golang Writer类的具体用法?Golang Writer怎么用?Golang Writer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Writer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetMapAclients
func GetMapAclients(db autorc.Conn, sqlstr string, makeFlag string, golog syslog.Writer) []d.Aclient {
var aclientsmap []d.Aclient
if stmt, err := db.Prepare(sqlstr); err != nil {
golog.Err(err.Error())
} else {
if rows, res, err := stmt.Exec(); err != nil {
golog.Err(err.Error())
} else {
aclientsmap = make([]d.Aclient, len(rows))
for i, row := range rows {
aclientsmap[i].Id = row.Int(res.Map("id"))
aclientsmap[i].Phone = row.Str(res.Map("phone"))
aclientsmap[i].Opcode = row.Str(res.Map("opcode"))
aclientsmap[i].Nmake = makeFlag
aclientsmap[i].Nupdatemake = row.Localtime(res.Map("nupdate_make"))
}
}
}
return aclientsmap
}
示例2: xmlcheck
func xmlcheck(golog syslog.Writer, provider string, phone string, data []byte) {
// log.Println("GetUrl:xmlcheck check provider ", provider, "phone", phone)
//
// <SmsResponse>
// <version>1</version>
// <result>1</result>
// <resultstring>success</resultstring>
// <description></description>
// <partcount>1</partcount>
// <endcause></endcause>
//</SmsResponse>
v := Dataxml{}
err := xml.Unmarshal(data, &v)
if err != nil {
// fmt.Printf("error: %v", err)
golog.Err(err.Error())
blockphone(phone)
} else {
// fmt.Printf("Result: %q\n", v.Result)
golog.Info(v.Result)
}
}
示例3: GetSqlMainosTel
func GetSqlMainosTel(golog syslog.Writer, db sql.DB, sqlstr string) []domains.MainosTel {
var result []domains.MainosTel
rows, err := db.Query(sqlstr)
if err != nil {
golog.Err(err.Error())
}
defer rows.Close()
for rows.Next() {
var phone string
var smstext string
err := rows.Scan(&phone, &smstext)
if err != nil {
golog.Err(err.Error())
}
var mainostel domains.MainosTel
if !strings.HasPrefix(phone, "09") && !strings.Contains(phone, "070057") {
mainostel.Phone = phone
mainostel.Text = smstext
result = append(result, mainostel)
}
}
return result
}
示例4: configParse
func configParse(cfg *config, mainLogger *syslog.Writer) bool {
const KEY = 0
const VAL = 1
file, err := os.Open(CONFIG_PATH)
if err != nil {
return false
}
defer file.Close()
scanner := bufio.NewScanner(file)
newConf := false
for scanner.Scan() {
read := scanner.Text()
if len(read) > 0 && read[0] != '#' {
newConf = true
pair := strings.Split(read, "=")
trimmedKey := strings.TrimSpace(pair[KEY])
trimmedVal := strings.TrimSpace(pair[VAL])
val, _ := strconv.Atoi(trimmedVal)
configUpdate(cfg, trimmedKey, uint16(val))
mainLogger.Info(fmt.Sprintf("Custom setting found %s: %s", trimmedKey, trimmedVal))
}
}
if !newConf {
mainLogger.Info("No custom settings found, using defaults")
}
if err := scanner.Err(); err != nil {
log.Fatal("Error: could not parse config file")
}
return true
}
示例5: apiCount
func apiCount(s *mgo.Session, mlog *syslog.Writer) string {
itemCount, listCount, err := dbCountLists(s)
var countOut struct {
ItemCount int
List []struct {
Label string
Count int
}
}
countOut.ItemCount = listCount
countOut.List = make([]struct {
Label string
Count int
}, len(itemCount))
i := 0
for k, v := range itemCount {
countOut.List[i].Label = k
countOut.List[i].Count = v
i += 1
}
out, err := json.MarshalIndent(countOut, "", " ")
if err != nil {
mlog.Err("Error: could not properly construct json")
return "Error"
}
return string(out)
}
示例6: write
// Reads from a queue and writes to writer until the queue channel
// is closed. Signals to a WaitGroup when done.
func write(queue chan []byte, writer *syslog.Writer, wg *sync.WaitGroup) {
defer wg.Done()
fmt.Println("writer started")
var totalWrites int64 = 0
var cumuWriteDuration int64 = 0
for line := range queue {
start := time.Now()
writer.Write(line)
//var _ = line
totalWrites++
cumuWriteDuration += time.Now().Sub(start).Nanoseconds() / 1000
}
fmt.Println("writer shutting down")
avgWriteDuration := float64(cumuWriteDuration) / float64(totalWrites)
fmt.Println("total lines written: ", totalWrites)
fmt.Printf("avg write duration (us): %.3v\n", avgWriteDuration)
}
示例7: SendSMS
func SendSMS(golog syslog.Writer, clphonenum string, text string, site string) {
var smsout d.Smsout
if text == "" {
golog.Info("Send first SMS on " + clphonenum)
smsout.Phoneto = strings.Replace(clphonenum, "358", "0", 1)
smsout.Text = "Soita! Miia. puh. 070095943"
smsout.Phonefrom = "070095943"
smsout.Opcode = "notImpotent"
smsout.Nmake = "notImpotent"
} else {
golog.Info("Send Second SMS on " + clphonenum + " " + text)
smsout.Phoneto = strings.Replace(clphonenum, "358", "0", 1)
smsout.Text = text
smsout.Phonefrom = "070095943"
smsout.Opcode = "notImpotent"
smsout.Nmake = "notImpotent"
}
pr.SmsSendBy("sonera", smsout, golog)
}
示例8: apiGet
func apiGet(s *mgo.Session, label string, todo string, mlog *syslog.Writer) string {
if len(label) == 0 {
return ""
}
list, err := dbQuery(s, label)
if err != nil {
mlog.Err("Error: db query went bad: " + err.Error())
return "Error"
}
todos := make([]TodoItem, len(list))
count := 0
for i, todo := range list {
todos[i].Text = todo.Text
todos[i].Id = todo.Id.Hex()
count += 1
}
jsonOut := struct {
Label string
Count int
Todos []TodoItem
}{label, count, todos}
out, err := json.MarshalIndent(jsonOut, "", " ")
if err != nil {
mlog.Err("Error: could not properly construct json")
return "Error"
}
return string(out)
}
示例9: StartDrainer
func (this *Server) StartDrainer(address string, filter EntryFilter) *Drainer {
c := make(chan Entry)
listener := &Listener{
Channel: c,
Filter: filter,
LastEntry: time.Now(),
}
this.AddListener <- listener
drainer := &Drainer{
Address: address,
Filter: filter,
server: this,
listener: listener,
terminate: make(chan bool, 1),
}
go func() {
var w *syslog.Writer
var err error
for entry := range Throttle(c, 100) {
for {
// If we terminated give up
select {
case <-drainer.terminate:
return
default:
}
// Connect
if w == nil {
log.Printf("connecting to syslog://%v\n", address)
w, err = syslog.Dial("tcp", address, syslog.LOG_INFO, "")
if err != nil {
w = nil
time.Sleep(time.Second * 5)
continue
}
}
// Send the message
_, err = w.Write(entry.Line())
if err != nil {
w.Close()
w = nil
time.Sleep(time.Second * 5)
continue
}
// Successfully sent the message so break
break
}
}
}()
return drainer
}
示例10: apiRemove
func apiRemove(s *mgo.Session, label string, id string, mlog *syslog.Writer) string {
if len(label) == 0 {
return ""
}
err := dbRemove(s, label, MongoTodo{Id: bson.ObjectIdHex(id), Text: ""})
if err != nil {
mlog.Err("Error: db remove went bad: " + err.Error())
return "Error"
}
return "Removing: " + id + " from: " + label
}
示例11: apiAdd
func apiAdd(s *mgo.Session, label string, todo string, mlog *syslog.Writer) string {
if len(label) == 0 {
return ""
}
newTodo := MongoTodo{Id: bson.NewObjectId(), Text: todo}
err := dbInsert(s, label, newTodo)
if err != nil {
mlog.Err("Error: db insert went bad: " + err.Error())
return "Error"
}
return newTodo.Id.Hex()
}
示例12: InsertSmsRecord
func InsertSmsRecord(db autorc.Conn, sqlstr string, golog syslog.Writer) {
if stmt, err := db.Prepare(sqlstr); err != nil {
golog.Err(err.Error())
} else {
if _, _, err := stmt.Exec(); err != nil {
golog.Err(err.Error())
}
}
}
示例13: GetLastMainos
func GetLastMainos() {
var golog syslog.Writer
var config domains.Config
confstr := config.Database.User + ":" + config.Database.Passwd + "@/" + config.Database.Database + "?parseTime=true"
db, err := sql.Open("mysql", confstr)
if err != nil {
golog.Err(err.Error())
}
defer db.Close()
sql2.GetSqlMainosTel(golog, *db, "select count(*) from calls where cdate>=curdate()")
}
示例14: sendToSyslog
func sendToSyslog(message *nats.Msg, syslog *syslog.Writer) {
logMessage := buildLogMessage(message)
logger.Debug("message-sent-to-syslog", lager.Data{"message": logMessage})
err := syslog.Info(logMessage)
if err != nil {
logger.Error("logging-to-syslog-failed", err)
stop <- true
}
}
示例15: fanControl
func fanControl(cfg *config, mainLogger *syslog.Writer) {
currTemp := getTemp()
prevTemp := currTemp
prevLvl := uint16(1)
currLvl := getFanLevel(cfg, currTemp, prevTemp, prevLvl)
for {
if prevLvl != currLvl {
setFanLevel(currLvl)
mainLogger.Debug(fmt.Sprintf("Fan level changed: %d -> %d (%d -> %d)",
prevLvl, currLvl, prevTemp, currTemp))
} else {
mainLogger.Debug(fmt.Sprintf("Fan level remained: %d (%d -> %d)", currLvl, prevTemp, currTemp))
}
time.Sleep(time.Second * time.Duration(cfg.pollInterval))
prevTemp = currTemp
currTemp = getTemp()
prevLvl = currLvl
currLvl = getFanLevel(cfg, currTemp, prevTemp, prevLvl)
}
}