source: code/trunk/vendor/modernc.org/ccgo/v3/lib/dmesg.go@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 849 bytes
Line 
1// Copyright 2021 The CCGO Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build ccgo.dmesg
6// +build ccgo.dmesg
7
8package ccgo // import "modernc.org/ccgo/v3/lib"
9
10import (
11 "fmt"
12 "os"
13 "path/filepath"
14 "strings"
15)
16
17const dmesgs = true
18
19var (
20 pid = fmt.Sprintf("[%v %v] ", os.Getpid(), filepath.Base(os.Args[0]))
21 logf *os.File
22)
23
24func init() {
25 var err error
26 if logf, err = os.OpenFile("/tmp/ccgo.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY|os.O_SYNC, 0644); err != nil {
27 panic(err.Error())
28 }
29}
30
31func dmesg(s string, args ...interface{}) {
32 if s == "" {
33 s = strings.Repeat("%v ", len(args))
34 }
35 s = fmt.Sprintf(s, args...)
36 s = pid + s
37 switch {
38 case len(s) != 0 && s[len(s)-1] == '\n':
39 fmt.Fprint(logf, s)
40 default:
41 fmt.Fprintln(logf, s)
42 }
43}
Note: See TracBrowser for help on using the repository browser.