core_logging

package
v0.0.0-...-99e5d07 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: MIT, Apache-2.0, BSD-3-Clause, + 1 more Imports: 12 Imported by: 0

README

Blackspace Core Logging Library


This document outlines how to effectively make use of this library.

go get github.com/BlackspaceInc/BlackspacePlatform/src/libraries/core/core-logging

Requires:

  • Go >= 1.12

This document outlines how to effectively make use of this library.

import (
	log "github.com/BlackspaceInc/BlackspacePlatform/src/libraries/core/core-logging"
)

// Log output is buffered and written periodically using Flush. Programs
// should call Flush before exiting to guarantee all log output is written.
//
// By default, all log statements write to standard error.
// This package provides several flags that modify this behavior.
// As a result, flag.Parse must be called before any logging is done.
//
//	-logtostderr=true
//		Logs are written to standard error instead of to files.
//	-alsologtostderr=false
//		Logs are written to standard error as well as to files.
//	-stderrthreshold=ERROR
//		Log events at or above this severity are logged to standard
//		error as well as to files.
//	-log_dir=""
//		Log files will be written to this directory instead of the
//		default temporary directory.
//
//	Other flags provide aids to debugging.
//
//	-log_backtrace_at=""
//		When set to a file and line number holding a logging statement,
//		such as
//			-log_backtrace_at=gopherflakes.go:234
//		a stack trace will be written to the Info log whenever execution
//		hits that statement. (Unlike with -vmodule, the ".go" must be
//		present.)
//	-v=0
//		Enable V-leveled logging at the specified level.
//	-vmodule=""
//		The syntax of the argument is a comma-separated list of pattern=N,
//		where pattern is a literal file name (minus the ".go" suffix) or
//		"glob" pattern and N is a V level. For instance,
//			-vmodule=gopher*=3
//		sets the V level to 3 in all Go files whose names begin "gopher".
func main() {
    // In this example, we want to show you that all the lines logged
    // end up in the myfile.log. You do NOT need them in your application
    // as all these flags are set up from the command line typically
    flag.Set("logtostderr", "false")     // By default klog logs to stderr, switch that off
    flag.Set("alsologtostderr", "false") // false is default, but this is informative
    flag.Set("stderrthreshold", "FATAL") // stderrthreshold defaults to ERROR, we don't want anything in stderr
    flag.Set("log_file", "myfile.log")   // log to a file

    // parse flags
    flag.Parse()

    // initialize the log object which will intuitively send logs some output defined by the client
    logs.InitLogs()
    logs.AddFlags(flag)
    // defer the flushing of logs until the process exits. Note - can define explicit conditions for this
    defer logs.FlushLogs()

    serviceName := "authentication_service"
    var logEngine = log.NewLogger(serviceName)
}

Documentation

Overview

Copyright 2019 The Blackspace Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(fs *pflag.FlagSet)

AddFlags registers this package's flags on arbitrary FlagSets, such that they point to the same value as the global flags.

func FlushLogs

func FlushLogs()

FlushLogs flushes logs immediately.

func GlogSetter

func GlogSetter(val string) (string, error)

GlogSetter is a setter to set glog level.

func InitLogs

func InitLogs()

InitLogs initializes logs the way we want for kubernetes.

func NewLogger

func NewLogger(prefix string) *log.Logger

NewLogger creates a new log.Logger which sends logs to klog.Info.

Types

type KlogWriter

type KlogWriter struct{}

KlogWriter serves as a bridge between the standard log package and the glog package.

func (KlogWriter) Write

func (writer KlogWriter) Write(data []byte) (n int, err error)

Write implements the io.Writer interface.

type LogFormatRegistry

type LogFormatRegistry struct {
	// contains filtered or unexported fields
}

LogFormatRegistry store klog format registry

func NewLogFormatRegistry

func NewLogFormatRegistry() *LogFormatRegistry

NewLogFormatRegistry return new init LogFormatRegistry struct

func (*LogFormatRegistry) Delete

func (lfr *LogFormatRegistry) Delete(name string) error

Delete specified log format logger

func (*LogFormatRegistry) Freeze

func (lfr *LogFormatRegistry) Freeze()

Freeze freezes the log format registry

func (*LogFormatRegistry) Get

func (lfr *LogFormatRegistry) Get(name string) (logr.Logger, error)

Get specified log format logger

func (*LogFormatRegistry) List

func (lfr *LogFormatRegistry) List() []string

List names of registered log formats (sorted)

func (*LogFormatRegistry) Register

func (lfr *LogFormatRegistry) Register(name string, logger logr.Logger) error

Register new log format registry to global logRegistry

func (*LogFormatRegistry) Set

func (lfr *LogFormatRegistry) Set(name string, logger logr.Logger) error

Set specified log format logger

type Options

type Options struct {
	LogFormat       string
	LogSanitization bool
}

Options has klog format parameters

func NewOptions

func NewOptions() *Options

NewOptions return new klog options

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags add logging-format flag

func (*Options) Apply

func (o *Options) Apply()

Apply set klog logger from LogFormat type

func (*Options) Get

func (o *Options) Get() (logr.Logger, error)

Get logger with LogFormat field

func (*Options) Validate

func (o *Options) Validate() []error

Validate verifies if any unsupported flag is set for non-default logging format

Directories

Path Synopsis
Package datapol contains functions to determine if objects contain sensitive data to e.g.
Package datapol contains functions to determine if objects contain sensitive data to e.g.

Jump to

Keyboard shortcuts

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