{"id":20736184,"url":"https://github.com/pthreat/slog","last_synced_at":"2025-07-23T08:34:07.443Z","repository":{"id":57058968,"uuid":"84614406","full_name":"pthreat/slog","owner":"pthreat","description":"A Simple PHP Logging class","archived":false,"fork":false,"pushed_at":"2017-03-20T02:30:08.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T19:13:32.560Z","etag":null,"topics":["console","log","logging","php","simple"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/pthreat.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":"2017-03-11T01:21:05.000Z","updated_at":"2017-03-11T01:23:15.000Z","dependencies_parsed_at":"2022-08-24T14:53:25.028Z","dependency_job_id":null,"html_url":"https://github.com/pthreat/slog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pthreat/slog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pthreat%2Fslog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pthreat%2Fslog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pthreat%2Fslog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pthreat%2Fslog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pthreat","download_url":"https://codeload.github.com/pthreat/slog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pthreat%2Fslog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266645150,"owners_count":23961658,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["console","log","logging","php","simple"],"created_at":"2024-11-17T05:46:41.019Z","updated_at":"2025-07-23T08:34:07.423Z","avatar_url":"https://github.com/pthreat.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slog (Simple Log)\n\n**A simple PHP logging class**\n\n## Preface\n\nSlog is a simple PHP logging class which you can easily include in any of your projects.\n\n## Installing Slog\n\n### You can clone the latest version from GIT\n```\ngit clone https://github.com/pthreat/slog.git\n```\n\n### Or just add Slog to your project via composer\n```\ncomposer require stange/slog\n```\n\n## Features\n\n- [x] ANSI output coloring\n- [x] Log to a file\n- [x] Log tags (see below)\n- [x] Prepend or append a log string\n- [x] Prefix your log messages with a specific date format\n\n## Examples\n\n### Basic Example\n\n```php\nuse \\stange\\logging\\Slog;\n\n$log\t=\tnew Slog();\n$log-\u003elog('Scotty, beam me up!');\n\n```\n---\n\n### Using specific log types types and ANSI coloring capabilities\n\nSlog contains different methods for you to inform different types of log messages.\nAlso, by default, SLog will colorize your log output\n\n```php\nuse \\stange\\logging\\Slog;\n\n$log\t=\tnew Slog();\n\n$log-\u003elog('test message');\n$log-\u003edebug('Debug');\n$log-\u003einfo('Info');\n$log-\u003ewarning('Warning');\n$log-\u003eerror('Error');\n$log-\u003eemergency('Emergency');\n$log-\u003esuccess('Success');\n```\n\nResult:\n\n![alt tag](https://raw.githubusercontent.com/pthreat/slog/master/screenshots/colors.png)\n\nYou can of course, disable output coloring\n\n```php\nuse \\stange\\logging\\Slog;\n\n$log\t=\tnew Slog([\n                   'colors' =\u003e FALSE\n]);\n\n//You can disable colors at runtime too\n\n//$log-\u003euseColors(FALSE);\n\n$log-\u003edebug('Debug');\n```\n---\n\n### Log to a file\n\n```php\nuse \\stange\\logging\\Slog;\n\n$log\t=\tnew Slog([\n                   'file'=\u003e'out.log'\n]);\n\n$log-\u003elog('Log to a file (and to stdout)');\n```\n\n**NOTE:** ANSI colors will not be logged into the file\n\n---\n\n### File only output example\n\nIn case you don't want to output to stdout, you can pass in **'echo'=\u003eFALSE** in the constructor\nor disable stdout output by using **Slog::setEcho(FALSE)**.\n\n```php\nuse \\stange\\logging\\Slog;\n\n$log\t=\tnew Slog([\n                   'file'   =\u003e 'out.log',\n                   'echo'   =\u003e FALSE\n\n]);\n\n$log-\u003elog(\"No stdout log, file only\");\n\n```\n---\n\n## Log Tagging\n\n###### Logging is a great thing, however sometimes the amount of logged information can be cumbersome.\n\n** A cool feature of Slog is that you can tag your logs. **\n\n### Tag your logs? What do you mean?\n\nI mean that you can use certain \"tags\" in your log messages for logging messages of a certain kind but not others of a different kind.\n\nHere is a brief example of two tagged log messages:\n\n```php\nuse \\stange\\logging\\Slog;\n\n$log\t=\tnew Slog([\n                   'tagId'=\u003e'@@@'\n]);\n\n$log-\u003elog('tagOne@@@Hello! this is a tagged message with the tag tagOne');\n$log-\u003elog('tagTwo@@@This is another tagged message with the tagTwo');\n\n```\n\nIn the previous example, both messages will be logged and shown through stdout.\n\nHowever, now, if we add a log tag to slog things will be a bit different.\n\nOnly messages which match the tag \"tagOne\" will be logged.\nMessages containing the tag \"tagTwo\" will be discarded, i.e: not logged.\n\n```php\n$log\t=\tnew Slog([\n                       'tagId' =\u003e '@@@',   //Set the tag identifier to @@@\n                       'tags'  =\u003e 'tagOne' //Log messages only from tagOne \n]);\n\n$log-\u003elog('tagOne@@@Hello! this is a tagged message with the tag tagOne');\n\n//The next message will not be logged since we specified that only messages\n//containing the tag \"tagOne\" will be logged.\n\n$log-\u003elog('tagTwo@@@This is another tagged message with the tagTwo');\n\n```\n\nYou can log multiple tags if you need to, this would be a good idea when you want to increase your log verbosity\n\n```php\n$log\t=\tnew Slog([\n                       'tagId' =\u003e '@@@',              //Set the tag identifier to @@@\n                       'tags'  =\u003e ['tagOne','tagTwo'] //Log messages from tagOne AND tagTwo\n]);\n\n$log-\u003elog('tagOne@@@Hello! this is a tagged message with the tag tagOne');\n$log-\u003elog('tagTwo@@@This is another tagged message with the tagTwo');\n\n```\n\n### Adding or removing log tags on the run\n\nYou can add or remove a tag at any given point in time through the methods:\n\n- **Slog::removeTag($tag)** Removes a tag \n- **Slog::addTag($tag)** Specifies that messages containing a tag should be logged\n- **Slog::unsetTags()** Log everything\n\n\n### Loggable Trait and Loggable Interface\n\nAs an extra, I have included a simple logging trait which will enable you to use said trait\nin your own classes to make said class \"Loggable\", this trait contains three main methods:\n\n- **Loggable::setLog(LogInterface $log)**\n- **Loggable::getLog()**\n- **Loggable::log($message,$type=NULL)**\n\n**NOTE:** The trait will also prepend the __CLASS__ name to the log, in this way, if you have multiple classes\nwhich make use of the loggable trait, you can identify which logs come from one class and which other logs come \nfrom another\n\n### Trait and Loggable interface implementation example\n\n```php\nnamespace myProject{\n\n\t/**\n\t * Add the loggable interface to indicate to other class methods \n\t * that this class has logging capabilities.\n\t */\n\n\tuse \\stange\\logging\\slog\\iface\\Loggable\tas\tLoggableInterface;\n\n\tclass MyClass implements LoggableInterface{\n\n\t\t//Make the class \"Loggable\" by using the loggable trait\n\t\tuse \\stange\\logging\\slog\\traits\\Loggable;\n\n\t\tpublic function doStuff(){\n\n\t\t\t$this-\u003elog('stuff@@@Doing stuff!');\n\n\t\t}\n\n\t\tpublic function doOtherStuff(){\n\n\t\t\t$this-\u003elog('otherStuff@@@Doing other stuff!','info');\n\n\t\t}\n\n\t}\n\n\tclass MyOtherClass implements LoggableInterface{\n\n\t\tuse \\stange\\logging\\slog\\traits\\Loggable;\n\n\t\tpublic function doSomething(){\n\n\t\t\t$this-\u003elog('Doing something!','success');\n\n\t\t}\n\n\t}\n\n}\n```\n\n### With the previous code we could easily do the following implementation\n\n```php\n\n\tnamespace myProject;\n\n\tuse \\stange\\logging\\Slog();\n\n\t$log     =  new Slog([\n                              'tagId'\t=\u003e\t'@@@',\n\t\t\t\t\t\t\t\t\t\t'tags'\t=\u003e\t'stuff'\n\t]);\n\n\t$myClass      = new MyClass();\n\t$myOtherClass = new MyOtherClass();\n\n\t$myClass-\u003esetLog($log);\n\t$myOtherClass-\u003esetLog($log);\n\n\t$myClass-\u003edoStuff();\n\t$myClass-\u003edoingOtherStuff();\n\t$myOtherClass-\u003edoSomething();\n\n```\n---\n\n## TODO (next release)\n\n- [ ] Create an adapter pattern for logging messages in different places\n- [ ] Add logging adapters (Socket, File, Memory, etc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpthreat%2Fslog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpthreat%2Fslog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpthreat%2Fslog/lists"}