{"id":23107029,"url":"https://github.com/malekim/enlog","last_synced_at":"2025-07-25T22:12:44.299Z","repository":{"id":53618020,"uuid":"272362839","full_name":"malekim/enlog","owner":"malekim","description":"An enchanted logging library for GO","archived":false,"fork":false,"pushed_at":"2021-03-20T23:34:25.000Z","size":323,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T10:30:58.797Z","etag":null,"topics":["color-logging","file-logging","go","golang","logger","logging"],"latest_commit_sha":null,"homepage":"https://malekim.github.io/enlog/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malekim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-15T06:47:28.000Z","updated_at":"2021-03-20T23:33:14.000Z","dependencies_parsed_at":"2022-08-25T18:41:33.869Z","dependency_job_id":null,"html_url":"https://github.com/malekim/enlog","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekim%2Fenlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekim%2Fenlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekim%2Fenlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malekim%2Fenlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malekim","download_url":"https://codeload.github.com/malekim/enlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247092374,"owners_count":20882217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color-logging","file-logging","go","golang","logger","logging"],"created_at":"2024-12-17T01:12:08.141Z","updated_at":"2025-04-03T22:42:32.181Z","avatar_url":"https://github.com/malekim.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enlog \n[![codecov](https://codecov.io/gh/malekim/enlog/branch/master/graph/badge.svg)](https://codecov.io/gh/malekim/enlog)\n\nAn enchanted logging library for GO. It supports colored output and writing to .log files.\n\n## Install\n\nSimple go get it into your project:\n```bash\ngo get github.com/malekim/enlog\n```\n\n## Log types\n\n### Info\n\nInfo log shows messages in green color by default.\nPrefix is set to \"INFO\" by default.\nUseFile is set to false by default.\nFilePath is set to \"info.log\" by default.\n\n#### Usage\n\nYou can use methods: Info() and Infof()\n```go\nl := enlog.New()\nl.Info(\"Test info\")\nmsg := \"Test message\"\nl.Infof(\"Test message: %s\", message)\n```\n\n#### Example of info log\n\n```bash\nINFO: 2020/06/17 09:15:55 info.go:16: info\n```\n\n### Debug\n\nDebug log shows messages in cyan color by default.\nPrefix is set to \"DEBUG\" by default.\nUseFile is set to false by default.\nFilePath is set to \"debug.log\" by default.\n\n#### Usage\n\nYou can use methods: Debug() and Debugf()\n```go\nl := enlog.New()\nl.Debug(\"Test debug\")\nmsg := \"Test message\"\nl.Debugf(\"Test message: %s\", message)\n```\n\n#### Example of debug log\n\n```bash\nDEBUG: 2020/06/17 09:15:55 debug.go:17: debug\n```\n\n### Error\n\nError log shows messages in red color by default.\nPrefix is set to \"ERROR\" by default.\nUseFile is set to false by default.\nFilePath is set to \"error.log\" by default.\n\n#### Usage\n\n```go\nl := enlog.New()\nl.Error(\"Test error\")\nmsg := \"Test message\"\nl.Errorf(\"Test message: %s\", message)\n```\n\n#### Example of error log\n\n```bash\nERROR: 2020/06/17 09:15:55 error.go:17: error\n```\n\n### Trace\n\nTrace log shows messages in magenta color by default.\nPrefix is set to \"TRACE\" by default.\nUseFile is set to false by default.\nFilePath is set to \"trace.log\" by default.\n\n#### Usage\n\n```go\nl := enlog.New()\nl.Trace(\"Test trace\")\nmsg := \"Test message\"\nl.Tracef(\"Test message: %s\", message)\n```\n\n#### Example of trace log\n\n```bash\nTRACE: 2020/06/17 09:15:55 trace.go:17: trace\n```\n\n## Event after log\n\nThe event is called after every log. You can set it up like this:\n\n```go\nl := enlog.New()\nl.SetAfterLogEvent(func(logType string, message string) {\n  fmt.Printf(\"Type: %s, message %s\", logType, message)\n})\n```\n\n## Customization\n\nFields of enlog which contains settings of particular log types are:\n- InfoLog for log type info\n- DebugLog for log type debug\n- ErrorLog for log type error\n- TraceLog for log type trace\n\n```go\nl := enlog.New()\ninfoLog := l.InfoLog\ndebugLog := l.DebugLog\nerrorLog := l.ErrorLog\ntraceLog := l.TraceLog\n```\n\nExamples use InfoLog, but each of those log types are customizable in the same way.\n\n### Prefix\n\n```go\nl := enlog.New()\nl.InfoLog.SetPrefix(\"NEW\")\nl.InfoLog.GetPrefx() // returns string NEW\nl.Info(\"Test message\")\n```\n\nExample:\n```bash\nNEW: 2020/06/17 09:15:55 info.go:16: Test message\n```\n\n### File logs\n\nBy default logs are not saved to files. To change it you need to switch \"useFile\" parameter. \nIf error occurs during creating or opening the file, \"useFile\" automatically switches back to false.\n\n```go\nl := enlog.New()\nl.InfoLog.GetUseFile() // returns false\nl.InfoLog.SetUseFile(true)\nl.InfoLog.GetUseFile() // returns true\nl.Info(\"Test message\") // log shown in terminal and saved to info.log\nl.InfoLog.GetFilePath() // returns \"info.log\"\nl.InfoLog.SetFilePath(\"new.log\")\nl.InfoLog.GetFilePath() // returns \"new.log\"\nl.Info(\"Test message\") // log shown in terminal and saved to new.log\n```\n\n#### Single file log\n\nSometimes it is necessary to save all log messages to single file.\nIt is possible to set one file log for all log types.\n\n```go\nvar l *Enlog = New()\nnewFilePath := \"single.log\"\nl.InfoLog.SetFilePath(newFilePath)\nl.DebugLog.SetFilePath(newFilePath)\nl.TraceLog.SetFilePath(newFilePath)\nl.ErrorLog.SetFilePath(newFilePath)\nl.InfoLog.SetUseFile(true)\nl.DebugLog.SetUseFile(true)\nl.TraceLog.SetUseFile(true)\nl.ErrorLog.SetUseFile(true)\n\nl.Info(\"Info log is saved to single.log\")\nl.Debug(\"Debug log is saved to single.log\")\nl.Error(\"Error log is saved to single.log\")\nl.Trace(\"Trace log is saved to single.log\")\n```\n\nSetting filePath before useFile prevents enlog from creating default .log files.\n\n### Colors\n\nTo change default color you need to modify \"color\" parameter (uint8).\n\n```go\nl := enlog.New()\nl.InfoLog.GetColor() // returns 32\nl.InfoLog.SetColor(enlog.ColorRed)\nl.InfoLog.GetColor() // returns 31\n```\n\n## Road map\n\nRoad map for future releases:\n- custom date and time format of logs\n- chunk log files\n\n## Running tests\n\n```bash\ngo test -gcflags=-l -coverprofile=coverage.txt -covermode=atomic ./... \u0026\u0026  go tool cover -html=coverage.txt\n```\n\nNote that flag -gcflags=-l is necessary for bou.ke/monkey library.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalekim%2Fenlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalekim%2Fenlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalekim%2Fenlog/lists"}