goterm

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2019 License: MIT Imports: 1 Imported by: 0

README

goterm

Go library for detecting whether file descriptor is connected to a terminal.

Example

package main

import (
	"log"
	"os"
	"path/filepath"

	"github.com/karrick/goterm"
	"github.com/natefinch/lumberjack"
)

const (
	logsDirname    = "logs"
	logsFilename   = "service.log"
	logsMaxDays    = 30
	logsMaxBackups = 50
)

func main() {
	if !goterm.IsTerminal(os.Stderr.Fd()) {
		log.SetOutput(&lumberjack.Logger{
			Filename:   filepath.Join(logsDirname, logsFilename),
			MaxAge:     logsMaxDays,
			MaxBackups: logsMaxBackups,
		})
	}

	log.Printf("log output")
}

TODO

Add Windows support.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(fd uintptr) bool

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL