justlog

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2020 License: Apache-2.0 Imports: 5 Imported by: 1

README

justlog

justlog is log helper library for golang.

  • Prepare directory for log file in same directory with executed binary
  • Set stream in standard go logger to os.Stdout and log file

How to use

Import library

import (
	"github.com/dictor/justlog"
)

Main code : Put in front of your main function

log_path := justlog.MustPath(justlog.SetPath())
defer (justlog.MustStream(justlog.SetStream(log_path))).Close()
log.Println("Hello world!!")

Log file will be created like below tree.

├── binary
└── log
    └── 2020-01-24T14_19_04.txt

In log file and stdout,

2020/01/24 14:19:04 Hello world!!

Documentation

Overview

Wrapper of golang's standard logger. Provide feature of preparing log folder and attaching stdout and file stream to logger's stream with just two functions.

Index

Constants

This section is empty.

Variables

View Source
var ExePath string

This variable is setted as executed binary's directory path after SetPath() function is called.

Functions

func MustPath

func MustPath(path string, err error) string

Helper function for simple code. It cause panic when err isn't nil.

func MustStream

func MustStream(s *os.File, err error) *os.File

Helper function for simple code. It cause panic when err isn't nil.

func SetPath

func SetPath() (string, error)

Retrieve executed binary's directory path and prepare log folder. Log folder name is 'log' and it's created under retrieved path when it doesn't exist.

func SetStream

func SetStream(path string) (*os.File, error)

Open file handler with name as current time string and attach file handler to logger's stream.

Types

This section is empty.

Jump to

Keyboard shortcuts

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