2020年6月4日木曜日

開発環境

Go Systems Programming: Master Linux and Unix system level programming with Go (Mihalis Tsoukalos(著)、Packt Publishing)のChapter 3(Advanced Go Features)、Exercises 1、2、3、4、5、6、7、8、9、10.の解答を求めてみる。

コード

package main

import "fmt"

func main() {
 var s string
 fmt.Scanln(&s)
}

入出力結果(Zsh、PowerShell、Terminal)

% go doc log
package log // import "log"

Package log implements a simple logging package. It defines a type, Logger,
with methods for formatting output. It also has a predefined 'standard'
Logger accessible through helper functions Print[f|ln], Fatal[f|ln], and
Panic[f|ln], which are easier to use than creating a Logger manually. That
logger writes to standard error and prints the date and time of each logged
message. Every log message is output on a separate line: if the message
being printed does not end in a newline, the logger will add one. The Fatal
functions call os.Exit(1) after writing the log message. The Panic functions
call panic after writing the log message.

const Ldate = 1 << iota ...
func Fatal(v ...interface{})
func Fatalf(format string, v ...interface{})
…
% godoc log
PACKAGE DOCUMENTATION

package log
    import "log"

    Package log implements a simple logging package. It defines a type,
    Logger, with methods for formatting output. It also has a predefined
    'standard' Logger accessible through helper functions Print[f|ln],
    Fatal[f|ln], and Panic[f|ln], which are easier to use than creating a
    Logger manually. That logger writes to standard error and prints the
    date and time of each logged message. Every log message is output on a
    separate line: if the message being printed does not end in a newline,
    the logger will add one. The Fatal functions call os.Exit(1) after
    writing the log message. The Panic functions call panic after writing
    the log message.

CONSTANTS

const (
    Ldate         = 1 << iota     // the date in the local time zone: 2009/01/23
    Ltime                         // the time in the local time zone: 01:23:23
    Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
    Llongfile                     // full file name and line number: /a/b/c/d.go:23
    Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
    LUTC                          // if Ldate or Ltime is set, use UTC rather than the local time zone
    Lmsgprefix                    // move the "prefix" from the beginning of the line to before the message
    LstdFlags     = Ldate | Ltime // initial values for the standard logger
)
    These flags define which text to prefix to each log entry generated by
    the Logger. Bits are or'ed together to control what's printed. With the
    exception of the Lmsgprefix flag, there is no control over the order
    they appear (the order listed here) or the format they present (as
    described in the comments). The prefix is followed by a colon only when
    Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime
    (or LstdFlags) produce,

 2009/01/23 01:23:23 message

    while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,

 2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

FUNCTIONS

func Fatal(v ...interface{})
    Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf(format string, v ...interface{})
    Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

…
% sudo dtrace ./hw
dtrace: system integrity protection is on, some features will not be available

dtrace: no probes specified
% sudo dtruss ./hw
dtrace: system integrity protection is on, some features will not be available

SYSCALL(args)    = return
Hello, World!
open("/dev/dtracehelper\0"…
…
% go build main.go
% ./main 
10
% sudo dtrace ./main
dtrace: system integrity protection is on, some features will not be available

dtrace: no probes specified
% sudo dtruss ./main
dtrace: system integrity protection is on, some features will not be available

SYSCALL(args)    = return
open("/dev/dtracehelper\0"…
…
abcde
…
%          

0 コメント:

コメントを投稿