Documentation
¶
Index ¶
- Constants
- func CamelToKebab(s string) string
- func CamelToSep(s string, sep string) string
- func CamelToSnake(s string) string
- func FormatCount(count int, unit CountUnit) string
- func FormatFileSize(bytes int64) string
- func FormatFileSizeInt(bytes int) string
- func NewLogger(conf LogConfig) *slog.Logger
- func NewLoggerWithWriter(conf LogConfig, lw io.Writer) *slog.Logger
- type CountUnit
- type JsonFloat
- type LogConfig
Examples ¶
Constants ¶
View Source
const ( LOG_LEVEL_DEBUG = "DEBUG" LOG_LEVEL_INFO = "INFO" LOG_LEVEL_WARN = "WARN" LOG_LEVEL_ERROR = "ERROR" )
Variables ¶
This section is empty.
Functions ¶
func CamelToKebab ¶ added in v0.0.5
Example ¶
package main
import (
"fmt"
"github.com/OutOfBedlam/tine/util"
)
func main() {
fmt.Println(util.CamelToKebab("CamelToSnake"))
}
Output: camel-to-snake
func CamelToSep ¶ added in v0.0.5
func CamelToSnake ¶ added in v0.0.5
Example ¶
package main
import (
"fmt"
"github.com/OutOfBedlam/tine/util"
)
func main() {
fmt.Println(util.CamelToSnake("CamelToSnake"))
}
Output: camel_to_snake
func FormatCount ¶ added in v0.0.2
Example ¶
package main
import (
"fmt"
"github.com/OutOfBedlam/tine/util"
)
func main() {
fmt.Println(util.FormatCount(0, util.CountUnitLines))
fmt.Println(util.FormatCount(1, util.CountUnitLines))
fmt.Println(util.FormatCount(2, util.CountUnitLines))
}
Output: 0 lines 1 line 2 lines
func FormatFileSize ¶
ByteSize returns a human-readable byte size string.
Example ¶
package main
import (
"fmt"
"github.com/OutOfBedlam/tine/util"
)
func main() {
fmt.Println(util.FormatFileSizeInt(0))
fmt.Println(util.FormatFileSize(1))
fmt.Println(util.FormatFileSizeInt(1024))
fmt.Println(util.FormatFileSize(1024 * 1024))
fmt.Println(util.FormatFileSize(1024 * 1024 * 1024))
fmt.Println(util.FormatFileSize(1024 * 1024 * 1024 * 1024))
fmt.Println(util.FormatFileSize(1024 * 1024 * 1024 * 1024 * 1024))
}
Output: 0B 1B 1.00KB 1.00MB 1.00GB 1.00TB 1.00PB
func FormatFileSizeInt ¶
func NewLogger ¶
Example ¶
// This example demonstrates how to create a new logger with different log levels.
// The logger is configured to write to a file and the log level is set to INFO.
conf := LogConfig{
Path: "-", // "-" writes to stdout, "" discard logging, otherwise writes to a file
Level: LOG_LEVEL_WARN,
NoColor: true,
Timeformat: "no-time-for-test",
}
logger := NewLogger(conf)
logger.Debug("This is a debug message")
logger.Info("This is an info message")
logger.Warn("This is a warning message")
logger.Error("This is an error message")
Output: no-time-for-test WRN This is a warning message no-time-for-test ERR This is an error message
Types ¶
type JsonFloat ¶ added in v0.0.6
func (JsonFloat) MarshalJSON ¶ added in v0.0.6
Example ¶
package main
import (
"fmt"
"github.com/OutOfBedlam/tine/util"
)
func main() {
jf := util.JsonFloat{Value: 3.1415926535, Decimal: 2}
b, err := jf.MarshalJSON()
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
Output: 3.14
type LogConfig ¶
type LogConfig struct {
Path string `toml:"path"`
NoColor bool `toml:"no_color,omitempty"`
AddSource bool `toml:"add_source,omitempty"`
Timeformat string `toml:"timeformat,omitempty"`
Level string `toml:"level"`
MaxSize int `toml:"max_size"`
MaxAge int `toml:"max_age"`
MaxBackups int `toml:"max_backups"`
Compress bool `toml:"compress,omitempty"`
Chown string `toml:"chown,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.