Documentation ¶
Overview ¶
Package sd provides methods to write to the systemd-journal.
Index ¶
- Constants
- Variables
- func Set_default_colors(colors map[Priority]Writer_option)
- func Set_default_disable_journal(disable bool) option
- func Set_default_remove_ansi(rm remove_ansi_escape) option
- func Set_default_remove_ansi_escape(rm remove_ansi_escape)
- func Set_default_writer(w io.Writer) option
- func Set_default_writer_stderr() option
- func Set_default_writer_stdout() option
- func Set_field(name string, value interface{}) option
- func Set_message_id(uuid string)
- func Set_priority(p Priority) option
- func Set_remove_ansi(rm remove_ansi_escape) option
- func Set_writer(w io.Writer) option
- type Journal
- func (j *Journal) Alert(a ...interface{}) error
- func (j *Journal) Alert_a(fields []string, a ...interface{}) error
- func (j *Journal) Alert_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Alert_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Alert_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Alertf(format string, a ...interface{}) error
- func (j *Journal) Crit(a ...interface{}) error
- func (j *Journal) Crit_a(fields []string, a ...interface{}) error
- func (j *Journal) Crit_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Crit_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Crit_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Critf(format string, a ...interface{}) error
- func (j *Journal) Debug(a ...interface{}) error
- func (j *Journal) Debug_a(fields []string, a ...interface{}) error
- func (j *Journal) Debug_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Debug_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Debug_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Debugf(format string, a ...interface{}) error
- func (j *Journal) Emerg(a ...interface{}) error
- func (j *Journal) Emerg_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Emerg_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Err(a ...interface{}) error
- func (j *Journal) Err_a(fields []string, a ...interface{}) error
- func (j *Journal) Err_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Err_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Err_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Errf(format string, a ...interface{}) error
- func (j *Journal) Info(a ...interface{}) error
- func (j *Journal) Info_a(fields []string, a ...interface{}) error
- func (j *Journal) Info_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Info_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Info_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Infof(format string, a ...interface{}) error
- func (j *Journal) Notice(a ...interface{}) error
- func (j *Journal) Notice_a(fields []string, a ...interface{}) error
- func (j *Journal) Notice_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Notice_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Notice_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Noticef(format string, a ...interface{}) error
- func (o *Journal) Option(opt ...option) (previous option)
- func (j *Journal) Send(fields map[string]interface{}) error
- func (j *Journal) Set_add_go_code_fields(use bool)
- func (j *Journal) Set_default_fields(fields map[string]interface{})
- func (j *Journal) Set_writer_priority(p Priority) *Journal
- func (j *Journal) Stack_skip(skip int) *Journal
- func (j *Journal) Warning(a ...interface{}) error
- func (j *Journal) Warning_a(fields []string, a ...interface{}) error
- func (j *Journal) Warning_a_f(fields []string, format string, a ...interface{}) error
- func (j *Journal) Warning_m(fields map[string]interface{}, a ...interface{}) error
- func (j *Journal) Warning_m_f(fields map[string]interface{}, format string, a ...interface{}) error
- func (j *Journal) Warningf(format string, a ...interface{}) error
- func (j *Journal) Write(b []byte) (int, error)
- type Priority
- type Writer_option
Examples ¶
Constants ¶
const ( // bit flags Remove_journal remove_ansi_escape = 1 << iota Remove_writer )
const ( Sd_message = "MESSAGE" // Used in Set_default_fields(). systemd provides a default Sd_tag = "SYSLOG_IDENTIFIER" )
See http://www.freedesktop.org/software/systemd/man/SD_JOURNAL_SUPPRESS_LOCATION.html, or man sd_journal_print, for valid systemd journal fields.
Variables ¶
var ( Log_emerg = Priority(strconv.Itoa(int(syslog.LOG_EMERG))) Log_alert = Priority(strconv.Itoa(int(syslog.LOG_ALERT))) Log_crit = Priority(strconv.Itoa(int(syslog.LOG_CRIT))) Log_err = Priority(strconv.Itoa(int(syslog.LOG_ERR))) Log_warning = Priority(strconv.Itoa(int(syslog.LOG_WARNING))) Log_notice = Priority(strconv.Itoa(int(syslog.LOG_NOTICE))) Log_info = Priority(strconv.Itoa(int(syslog.LOG_INFO))) Log_debug = Priority(strconv.Itoa(int(syslog.LOG_DEBUG))) )
These are log/syslog.Priority values.
Functions ¶
func Set_default_colors ¶
func Set_default_colors(colors map[Priority]Writer_option)
Set default colors for io.Writer.
default: red (bold, highlight): Log_alert, Log_crti, Log_err, orange (bold, highlight): Log_warning, Log_notice
example: map[Priority]string{Log_err: ansi.ColorCode("green")}
func Set_default_disable_journal ¶
func Set_default_disable_journal(disable bool) option
Journal output will be disabled. Useful for just stdout/stderr logging with color.
func Set_default_remove_ansi ¶
func Set_default_remove_ansi(rm remove_ansi_escape) option
Sets the package level/default remove_ansi_escape and the current *Journal intance. Returns previous default remove_ansi_escape.
func Set_default_remove_ansi_escape ¶
func Set_default_remove_ansi_escape(rm remove_ansi_escape)
Set default_remove_ansi_escape will set the default value for a new Journal.
func Set_default_writer ¶
Set output to an additional io.Writer
func Set_default_writer_stderr ¶
func Set_default_writer_stderr() option
func Set_default_writer_stdout ¶
func Set_default_writer_stdout() option
func Set_field ¶
func Set_field(name string, value interface{}) option
Sets the journal field name to value. The field will be removed when value is nil. An invalid name will be silently ignored. See info for Sd_tag.
func Set_message_id ¶
func Set_message_id(uuid string)
Set_message_id sets the systemd MESSAGE_ID (UUID) for all Journal (Global) instances. Generate an application UUID with journalctl --new-id128. See man journalctl.
uuid is unset with ""
func Set_priority ¶
func Set_priority(p Priority) option
func Set_remove_ansi ¶
func Set_remove_ansi(rm remove_ansi_escape) option
func Set_writer ¶
Types ¶
type Journal ¶
type Journal struct {
// contains filtered or unexported fields
}
Journal can contain default systemd fields. See Set_default_fields().
Example ¶
j := sd.New_journal() j.Alert("Alert example") // COMMENT_2_BINARY = abcNULLabc m := map[string]interface{}{"COMMENT_1": "This function ran successfully", "COMMENT_2_BINARY": []byte{0x61, 0x62, 0x63, 0x00, 0x61, 0x62, 0x63}, } // Use: "journal -f --output verbose" to see fields j.Alert_m(m, "Alert_m exmaple") j.Alert_m_f(m, "Alert_m_f example: Salary: %v, Year: %v", 0.00, 2014)
Output:
func New_journal_m ¶
New_journal_m makes a Journal. The allowable interface{} values are string and []byte. A copy of []byte is made.
func (*Journal) Alert ¶
Alert sends a message with Log_alert Priority (syslog severity). a ...interface{}: fmt.Println formating will become MESSAGE; see man systemd.journal-fields.
func (*Journal) Alert_a ¶
Alert_a sends a message with Log_alert Priority (syslog severity). fields: your user-defined systemd.journal-fields. a ...interface{}: fmt.Println formating will become MESSAGE; see man systemd.journal-fields.
func (*Journal) Alert_a_f ¶
Alert_a_f sends a message with Log_alert Priority (syslog severity). The message is formed via fmt.Printf style arguments fields: your user-defined systemd.journal-fields. format string, a ...interface{}: see fmt.Printf.
func (*Journal) Alert_m ¶
Alert_m sends a message with Log_alert Priority (syslog severity). fields: your user-defined systemd.journal-fields. a ...interface{}: fmt.Println formating will become MESSAGE; see man systemd.journal-fields.
func (*Journal) Alert_m_f ¶
Alert_m_f sends a message with Log_alert Priority (syslog severity). The message is formed via fmt.Printf style arguments fields: your user-defined systemd.journal-fields. format string, a ...interface{}: see fmt.Printf.
func (*Journal) Alertf ¶
Alertf sends a message with Log_alert Priority (syslog severity). The message is formed via fmt.Printf style arguments format string, a ...interface{}: see fmt.Printf.
func (*Journal) Notice_a_f ¶
func (*Journal) Notice_m_f ¶
func (*Journal) Option ¶
func (o *Journal) Option(opt ...option) (previous option)
Option sets the options specified. It returns an option to restore the last arg's previous value.
func (*Journal) Send ¶
Send writes to the systemd-journal. The keys must be uppercase strings without a leading _. The other send methods are easier to use. See Info(), Infom(), Info_m_f(), etc. A MESSAGE key in field is the only required field.
func (*Journal) Set_add_go_code_fields ¶
Set_add_go_code_fields will add GO_FILE (<file name>#<line #>),and GO_FUNC fields to the journal Send() methods, Info(), Err(), Warning(), etc.. Default: use_go_code_fields = true.
func (*Journal) Set_default_fields ¶
Default fields are sent with every Send(). Do not include MESSAGE, or Priority, as these fields are always sent. The allowable interface{} values are string and []byte. A copy of []byte is made.
func (*Journal) Set_writer_priority ¶
Set_writer_priority set the priority for the write() receiver. You'll probably want to use Set_remove_ansi(sd.Remove_journal). Default: Log_info.
func (*Journal) Stack_skip ¶
Useful when file/line are not correct default: 4