{"id":18131482,"url":"https://github.com/crownedgrouse/slogan","last_synced_at":"2025-04-06T15:29:17.520Z","repository":{"id":57520700,"uuid":"234718950","full_name":"crownedgrouse/slogan","owner":"crownedgrouse","description":"Go(lang) logger library","archived":false,"fork":false,"pushed_at":"2024-12-12T00:57:51.000Z","size":22,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T21:34:40.282Z","etag":null,"topics":["golang","golang-library","logger","logging"],"latest_commit_sha":null,"homepage":null,"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/crownedgrouse.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-18T10:39:30.000Z","updated_at":"2023-06-03T11:40:54.000Z","dependencies_parsed_at":"2024-06-20T11:01:43.084Z","dependency_job_id":"de8c26d2-39fa-4ed1-9c79-aa6ebecdbce2","html_url":"https://github.com/crownedgrouse/slogan","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crownedgrouse%2Fslogan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crownedgrouse%2Fslogan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crownedgrouse%2Fslogan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crownedgrouse%2Fslogan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crownedgrouse","download_url":"https://codeload.github.com/crownedgrouse/slogan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247502593,"owners_count":20949297,"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":["golang","golang-library","logger","logging"],"created_at":"2024-11-01T12:07:38.761Z","updated_at":"2025-04-06T15:29:17.484Z","avatar_url":"https://github.com/crownedgrouse.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slogan #\n\n`slogan` is a logger library for Golang.\n\nFeatures :\n   - 10 Levels from \"silent\" to \"trace\", including POSIX levels\n   - Configurable format\n   - Configurable colors on individual items\n   - Easy elapsed time\n\n## Howto ##\n\n### Declare use ###\n\n```go\nimport (\n\t\"github.com/crownedgrouse/slogan\"\n)\n```\nAn alias (here 'log') can be used by setting it before import :\n\n```go\nimport (\n\tlog  \"github.com/crownedgrouse/slogan\"\n)\n```\n\n### Init ###\n\n```go main.go\npackage main\n\nimport (\n\tlog  \t\"github.com/crownedgrouse/slogan\"\n)\n\nfunc main() {\t\n\t\n\tlog.SetExitOnError(true) \n\n\t// Set verbosity\n\tlog.SetVerbosity(log.Ltrace)\n\t//\n\tlog.Runtime()\n\tlog.Trace(map[string]string{\"this is a\": \"map\"})\n\tlog.Debug(\"A debug message\")\n\tlog.Info(\"An informative message\")\n\tlog.Notice(\"A notification\")\n\tlog.Warning(\"A warning\")\n\tlog.Error(\"An Error\")\n\tlog.Critical(\"A critical message\")\n\tlog.Alert(\"An alert\")\n\tlog.Emergency(\"An Emergency\")\n}\n\n```\nWill produce (color not visible in this example):\n\n```\n$ go build\n$ ./main\n   debug     OS:linux ARCH:386 CPU:4 COMPILER:gc ROOT:/home/eric/git/goroot\n   trace     map[string]string\n %v: map[this is a:map]\n\n%v+: map[this is a:map]\n\n%#v: map[string]string{\"this is a\":\"map\"}\n   debug     A debug message\n   info      An informative message\n   notice    A notification\n   warning   A warning\n   error     An Error\n   debug     Immediate exit with code 4\n$ echo $?\n4\n```\n\n## Utilities ##\n\n### Show Runtime infos ###\n\nRuntime informations can be easily shown as a debug level with a uniq call.\n\n```go\nslogan.Runtime()\n```\n```shell\n   debug     OS:linux ARCH:386 CPU:4 COMPILER:gc ROOT:/home/eric/git/goroot\n```\n\n### Trace Go values ###\n\nCall to `Trace/1` will produce a trace log made of several lines. First line with 'trace' level and type of the value given. Below is written three usual ways to display Go values (%v, %v+ and %#v) separated with an empty line.\nThis format can be overrriden by your own preference (See 'Configuring/Formats' below).\n\n\n```go\n\tslogan.Trace(Something)\n```\n\n### Time elapsed ###\n\nDisplay how many time elapsed since program start or since last call to `ElapsedTime()` .\n\n```go\n    // Show time elapsed since last call to ElapsedTime() or since beginning at first call\n    slogan.ElapsedTime()\n    // Show time elapsed since beginning. This will reset start time reference\n    slogan.AllDone()\n```\nOutput will be a notice :\n\n```go\n  notice    All done in : 296.538µs\n```\n\n## Configuring ##\n\n`slogan` can be configured at beginning of your program (and also at any time inside your program).\n\n### Tags ###\n\nTags can be changed by overwritting `tags` map, with `GetTags/0` and `SetTags/1`.\n\n```go\nvar tags = [10]string{\n\t\t\"\",          // Prefix\n\t\t\"emergency\", // 1\n\t\t\"alert    \", // 2\n\t\t\"critical \", // 3\n\t\t\"error    \", // 4\n\t\t\"warning  \", // 5\n\t\t\"notice   \", // 6\n\t\t\"info     \", // 7\n\t\t\"debug    \", // 8\n\t\t\"trace    \", // 9\n}\n\n```\n\n### Output ###\n\nDefault output is on STDERR. Output can be set in a file by passing File Descriptor to \"slogan\".\n\n```go\n\tf, err := os.OpenFile(\"/var/log/myown.log\", os.O_RDWR|os.O_CREATE, 0755)\n\tif err != nil {\n\t\tlog.Critical(\"Cannot open file\")\n\t}\n\tlog.SetOutput(f)\n```\nColor will be disabled if output is not a Terminal unless forcing it.\n\n```go\n    log.SetForceColor(true)\n\n```\n\n`slogan` is using legacy \"log\" package underneath. `SetFlags` can be used to change \"log\" parameters.\n\nFor instance to show caller and line number in code :\n\n```go\n\tslogan.SetFlags(slogan.Lshortfile)  // No need to import \"log\". Same constants used in \"slogan\".\n```\n\nWill produce something like below : \n\n```shell\n   debug     main.go:17     A debug message\n   info      main.go:18     An informative message\n   notice    main.go:20     A warning\n   error     main.go:21     An Error\n```\nas well date/time information can be set this way.\n\nSet a prefix to any log :\n\n```go\n\tlog.SetPrefix(\"===\u003e \")\n```\n### Behaviour ###\n\nConsidering Warning as Error (and potentialy exit) :\n\n```go\n\tlog.SetWarningAsError(true)\n```\nSet or change verbosity from 0 (silent) to 9 (debug) :\n\n```go\nslogan.SetVerbosity(0)              // Silent totally logs\nslogan.SetVerbosity(slogan.Lsilent) // Same but using \"slogan\" Levels constant\n```\nBy setting verbosity, all logs with level lower or equal will be generated (if no immediate exit on error was set and no error occured) :\n\n```go\nlog.SetExitOnError(true) // Exit if log level reach Error or worst.\n```\nIf the case, the error message is generated and a debug level may appear, depending current verbosity, indicating that an immediate exit occured, and telling what is the program exit code. The exit code is equal to the level reached by the last fatal error, i.e 1 (emergency) to 4 (error) , or even 5 if warning considered error.\n\nSet option to silent empty log messages :\n\n```go\nslogan.SetNoEmpty(true) // Silent empty messages\n```\nNote: Exit on error is done even if message is empty and option set.\n\n### Formats ###\n\nFormats can be configured by settings new \"Sprintf\" values to the three arguments passed to `slogan` functions :\n\n- tag                  %[1]s\n- log                  %[2]s\n- caller (path:line)   %[3]s  (only if caller is required in \"log\" parameters)\n\n```go\n// Get current map\nformats := slogan.GetFormats()\n// Override format for caller : set caller in first\nformats[\"caller\"]= \"%-25[3]s %[1]s %[2]s \"\nslogan.SetFormats(formats)\nslogan.SetFlags(log.Lshortfile) // caller is required to be shown\n```\n\nDefault formats are : \n```go\nvar formats = map[string]string{\n\t\"fatal\"   : \"Immediate exit with code %d\",                        // immediate exit on error format\n\t\"trace\"   : \"%[1]T\\n %%v: %[1]v\\n\\n%%v+: %+[1]v\\n\\n%%#v: %#[1]v\", // multiline trace format\n\t\"empty\"   : \"%#v\",                                                // trace format for empty variable (avoid unuseful multiline)\n\t\"runtime\" : \"OS:%s ARCH:%s CPU:%d COMPILER:%s ROOT:%s\",           // runtime infos format\n\t\"default\" : \"   %[1]s %[2]s\",                                     // default log format\n\t\"caller\"  : \"   %[1]s %[3]s\\t %[2]s\",                             // default log format with caller (where)\n\t\"where\"   : \"%s:%d\",                                              // format for caller location path:linenumber\n\t\"alldone\" : \"All done in : %s\",                                   // all done time format\n\t\"elapsed\" : \"Elapsed time : %s\",                                  // elapsed time format\n}\n``` \n\n### Colors ###\n\nColor will be disabled if output is not a terminal. This can be avoid however by calling `SetForceColor/1` .\n\nColors can be changed by overwritting `colors` map, with `GetColors/0` and `SetColors/1`.\n\nSee [here](https://github.com/bclicn/color) for possible colors and other output (reverse, underlining, etc.)\n\n```go\nvar colors = map[int]string{\n\t10: \"Underline\",    // Caller\n\t9:  \"DarkGray\",     // trace\n\t8:  \"DarkGray\",     // debug\n\t7:  \"Purple\",       // info\n\t6:  \"Green\",        // notice\n\t5:  \"Yellow\",       // warning\n\t4:  \"LightRed\",     // error\n\t3:  \"Red\",          // critical\n\t2:  \"BLightRed\",    // alert\n\t1:  \"BRed\",         // emergency\n\t0:  \"\",             // Prefix\n}\n```\n\nAs well colorization of elements (called 'parts') in log line can be tuned by changing `parts` map, with `GetParts/0` and `SetParts/1`\n\n```go\nvar parts = map[string]bool{\n\t\"caller\": true,            // colorize caller (event if it is underlining)\n\t\"tag\":    true,            // colorize tag\n\t\"log\":    false,           // do not colorize log entry\n\t\"prefix\": false,           // do not colorize prefix\n}\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrownedgrouse%2Fslogan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrownedgrouse%2Fslogan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrownedgrouse%2Fslogan/lists"}