gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

default_notepad.go (2824B)


      1 // Copyright © 2016 Steve Francia <spf@spf13.com>.
      2 //
      3 // Use of this source code is governed by an MIT-style
      4 // license that can be found in the LICENSE file.
      5 
      6 package jwalterweatherman
      7 
      8 import (
      9 	"io"
     10 	"io/ioutil"
     11 	"log"
     12 	"os"
     13 )
     14 
     15 var (
     16 	TRACE    *log.Logger
     17 	DEBUG    *log.Logger
     18 	INFO     *log.Logger
     19 	WARN     *log.Logger
     20 	ERROR    *log.Logger
     21 	CRITICAL *log.Logger
     22 	FATAL    *log.Logger
     23 
     24 	LOG      *log.Logger
     25 	FEEDBACK *Feedback
     26 
     27 	defaultNotepad *Notepad
     28 )
     29 
     30 func reloadDefaultNotepad() {
     31 	TRACE = defaultNotepad.TRACE
     32 	DEBUG = defaultNotepad.DEBUG
     33 	INFO = defaultNotepad.INFO
     34 	WARN = defaultNotepad.WARN
     35 	ERROR = defaultNotepad.ERROR
     36 	CRITICAL = defaultNotepad.CRITICAL
     37 	FATAL = defaultNotepad.FATAL
     38 
     39 	LOG = defaultNotepad.LOG
     40 	FEEDBACK = defaultNotepad.FEEDBACK
     41 }
     42 
     43 func init() {
     44 	defaultNotepad = NewNotepad(LevelError, LevelWarn, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)
     45 	reloadDefaultNotepad()
     46 }
     47 
     48 // SetLogThreshold set the log threshold for the default notepad. Trace by default.
     49 func SetLogThreshold(threshold Threshold) {
     50 	defaultNotepad.SetLogThreshold(threshold)
     51 	reloadDefaultNotepad()
     52 }
     53 
     54 // SetLogOutput set the log output for the default notepad. Discarded by default.
     55 func SetLogOutput(handle io.Writer) {
     56 	defaultNotepad.SetLogOutput(handle)
     57 	reloadDefaultNotepad()
     58 }
     59 
     60 // SetStdoutThreshold set the standard output threshold for the default notepad.
     61 // Info by default.
     62 func SetStdoutThreshold(threshold Threshold) {
     63 	defaultNotepad.SetStdoutThreshold(threshold)
     64 	reloadDefaultNotepad()
     65 }
     66 
     67 // SetStdoutOutput set the stdout output for the default notepad. Default is stdout.
     68 func SetStdoutOutput(handle io.Writer) {
     69 	defaultNotepad.outHandle = handle
     70 	defaultNotepad.init()
     71 	reloadDefaultNotepad()
     72 }
     73 
     74 // SetPrefix set the prefix for the default logger. Empty by default.
     75 func SetPrefix(prefix string) {
     76 	defaultNotepad.SetPrefix(prefix)
     77 	reloadDefaultNotepad()
     78 }
     79 
     80 // SetFlags set the flags for the default logger. "log.Ldate | log.Ltime" by default.
     81 func SetFlags(flags int) {
     82 	defaultNotepad.SetFlags(flags)
     83 	reloadDefaultNotepad()
     84 }
     85 
     86 // SetLogListeners configures the default logger with one or more log listeners.
     87 func SetLogListeners(l ...LogListener) {
     88 	defaultNotepad.logListeners = l
     89 	defaultNotepad.init()
     90 	reloadDefaultNotepad()
     91 }
     92 
     93 // Level returns the current global log threshold.
     94 func LogThreshold() Threshold {
     95 	return defaultNotepad.logThreshold
     96 }
     97 
     98 // Level returns the current global output threshold.
     99 func StdoutThreshold() Threshold {
    100 	return defaultNotepad.stdoutThreshold
    101 }
    102 
    103 // GetStdoutThreshold returns the defined Treshold for the log logger.
    104 func GetLogThreshold() Threshold {
    105 	return defaultNotepad.GetLogThreshold()
    106 }
    107 
    108 // GetStdoutThreshold returns the Treshold for the stdout logger.
    109 func GetStdoutThreshold() Threshold {
    110 	return defaultNotepad.GetStdoutThreshold()
    111 }