From 2301baefd187da31b097203a88153e0df5ba2b2f Mon Sep 17 00:00:00 2001 From: rjbasitali Date: Sun, 25 Jul 2021 15:41:48 +0500 Subject: [PATCH] license and readme --- LICENSE | 7 +++++++ README.md | 7 +++++++ doc.go | 38 ++++++++++++++++++++++++++++++++++++++ logger_level.go | 11 +++++++++++ 4 files changed, 63 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 doc.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..764fe5a --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2021 Basit Ali + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5ef71c6 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# go-log +A Go logging library that provides simple leveled logging. + +## Documentation +Documentation for the following library can be found at https://pkg.go.dev/github.com/rjbasitali/go-log + +[![GoDoc](https://godoc.org/github.com/rjbasitali/go-log?status.svg)](https://pkg.go.dev/github.com/rjbasitali/go-log) \ No newline at end of file diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..89069be --- /dev/null +++ b/doc.go @@ -0,0 +1,38 @@ +/* +Package log provides simple leveled logging. + +Usage + +To use this package get the logger using: + + logger = log.NewLogger(os.Stdout) + +You can also get a leveled logger using: + + Logger = log.NewLogger(os.Stdout).Level(6) + +(Note that we are passing Level as 6, which will log everything) + +Once you have the logger you can use it to log stuff like: + + logger.Log("Hello world!") + + logger.Inform("Someone knocked!") + + logger.Alert("Intruder!") + + logger.Warn("Threat found.") + +Or for formatted logging: + + logger.Logf("Hello %s!", "John") + + logger.Informf("%s knocked!", "John") + + logger.Alertf("Intruder of level %d", 9) + + logger.Warnf("Found %q threat!", "Impersonator") + +*/ + +package log diff --git a/logger_level.go b/logger_level.go index c77d8e6..4ea76ac 100644 --- a/logger_level.go +++ b/logger_level.go @@ -10,9 +10,20 @@ const ( traceFlag = 0b00100000 // L6 ) +// Level returns a leveled logger, level can be from 1 to 6. +// Level 1 — Alert or Error +// Level 2 — Warn +// Level 3 — Highlight +// Level 4 — Inform +// Level 5 — Log +// Level 6 — Trace +// Anything above 6 as level will be considered Level 6. +// Pass 0 to output no logs. func (l myLogger) Level(level uint8) Logger { logger := myLogger{Writer: l.Writer, prefix: l.prefix, begin: l.begin} switch level { + case 0: + logger.level = 0 case 1: logger.level = alertFlag | errorFlag case 2: