logging.go
author Mikael Berthe <mikael@lilotux.net>
Wed, 23 Feb 2022 22:56:53 +0100
changeset 45 ea6a9ba7a3c8
parent 34 b70346ff153d
permissions -rw-r--r--
Display existing hard links in result sets This is a breaking change in the plain text output, but somehow the list displayed in case of existing hard links was arbitrary, since the all the hardlinked filenames were not displayed. Here's a sample JSON result with this patch: { "file_size": 9216, "paths": [ "test_tree/f09-1_5.raw", "test_tree/f09-4_5.raw" ], "links": { "test_tree/f09-1_5.raw": [ "test_tree/f09-2_5.raw", "test_tree/f09-3_5.raw" ], "test_tree/f09-4_5.raw": [ "test_tree/f09-5_5.raw" ] } } Here the 5 files have the same contents, but there are two hardlink groups: "test_tree/f09-1_5.raw" "test_tree/f09-2_5.raw" "test_tree/f09-3_5.raw" are hard-linked, and "test_tree/f09-4_5.raw" "test_tree/f09-5_5.raw" are hard-linked. Here's the same set displayed With the regular text output: Group #5 (2 files * 9216 bytes): test_tree/f09-1_5.raw test_tree/f09-2_5.raw test_tree/f09-3_5.raw test_tree/f09-4_5.raw test_tree/f09-5_5.raw (The link file names are indented using 1 space character.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
/*
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
 * Copyright (C) 2014-2018 Mikael Berthe <mikael@lilotux.net>
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
 *
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
 * This program is free software; you can redistribute it and/or modify
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
 * it under the terms of the GNU General Public License as published by
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
 * the Free Software Foundation; either version 2 of the License, or (at
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
 * your option) any later version.
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
 *
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful, but
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
 * WITHOUT ANY WARRANTY; without even the implied warranty of
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
 * General Public License for more details.
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
 *
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
 * USA
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
 */
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    20
package main
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    21
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
import (
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
	"fmt"
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
	"log"
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
	"os"
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
type myLogT struct {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    29
	verbosity int
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    32
func (l *myLogT) Printf(level int, format string, args ...interface{}) {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
	if level > l.verbosity {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
		return
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
	}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
	if level >= 0 {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
		log.Printf(format, args...)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    38
		return
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
	}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
	// Error message without timestamp
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
	fmt.Fprintf(os.Stderr, format, args...)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
func (l *myLogT) Println(level int, args ...interface{}) {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
	if level > l.verbosity {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    46
		return
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    47
	}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    48
	if level >= 0 {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    49
		log.Println(args...)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
		return
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
	}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    52
	// Error message without timestamp
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    53
	fmt.Fprintln(os.Stderr, args...)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    54
}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    55
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    56
func (l *myLogT) Fatal(args ...interface{}) {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    57
	log.Fatal(args...)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    58
}
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    59
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
func (l *myLogT) SetBenchFlags() {
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
	log.SetFlags(log.LstdFlags | log.Lmicroseconds)
b70346ff153d Split goduf.go into several files
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    62
}