{"id":36401070,"url":"https://github.com/easy-framework/easy-log","last_synced_at":"2026-01-14T01:38:33.769Z","repository":{"id":56974231,"uuid":"95791263","full_name":"easy-framework/easy-log","owner":"easy-framework","description":"Write log easily","archived":false,"fork":false,"pushed_at":"2018-06-23T15:59:44.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-09T14:12:18.177Z","etag":null,"topics":["logger","php-log","php-logger"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/easy-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-29T15:21:44.000Z","updated_at":"2025-05-13T09:37:20.000Z","dependencies_parsed_at":"2022-08-21T11:50:28.790Z","dependency_job_id":null,"html_url":"https://github.com/easy-framework/easy-log","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/easy-framework/easy-log","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-framework%2Feasy-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-framework%2Feasy-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-framework%2Feasy-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-framework%2Feasy-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easy-framework","download_url":"https://codeload.github.com/easy-framework/easy-log/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-framework%2Feasy-log/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["logger","php-log","php-logger"],"created_at":"2026-01-11T16:08:57.761Z","updated_at":"2026-01-14T01:38:33.764Z","avatar_url":"https://github.com/easy-framework.png","language":"PHP","readme":"# EASY LOG\n\n\u003e Write log easily\n\n# How to use?\n\n\u003e　composer require easy-framework/easy-log\n\n# Code\n\n```php\n\u003c?php\n/****************************************************\n *                    Easy Log                      *\n *                                                  *\n *                    TIERGB                        *\n *           \u003chttps://github.com/TIGERB\u003e            *\n *                                                  *\n ****************************************************/\n\nnamespace Easy;\n\nuse Exception;\n\n/**\n * log class\n * \n * 特点：相比其他日志类，一起请求只会最终打印一次日志从而降低到一次磁盘I/O\n * \n * 使用说明：\n * Log::debug(...)　-\u003e debug日志\n * Log::notice(...) -\u003e　提醒日志\n * Log::warning(...) -\u003e 警告日志\n * Log::error(...)  -\u003e 错误日志　\n */\nclass Log\n{\n\t/**\n\t * log buffer\n\t *\n\t * @var array\n\t */\n    private $buffer = [\n        \"\\n\"\n        // \"\\n---date---|---level---|---pid---|---memeory---|---log---\\n\"\n    ];\n    \n\n    /**\n\t * log method support\n\t *\n\t * @var array\n\t */\n    private $methodSupport = [\n        'debug',\n        'notice',\n        'warning',\n        'error'\n    ];\n    \n    /**\n\t * class private variable change allow list\n\t *\n\t * @var array\n\t */\n\tprivate $variablesAllow = [\n        'logPath',\n        'logFileSize',\n        'logFileName'\n    ];\n\n\t/**\n\t * the log file name\n\t *\n\t * @var string\n\t */\n    private $logFileName = '';\n\n    /**\n\t * the final log name include the path\n\t *\n\t * @var string\n\t */\n    private $finalFileName = '';\n\n    /**\n\t * the log path\n\t *\n\t * @var string\n\t */\n    private $logPath = '/tmp/easy';\n\n    /**\n\t * the log file size\n\t *\n\t * @var int unit/M\n\t */\n    private $logFileSize = 512;\n\n    /**\n\t * log\n\t *\n\t * @var string\n\t */\n    private $log = '';\n\n    /**\n     * instance\n     * \n     * @var object\n     */\n    private static $_instance;\n  \n    /**\n     * construct function\n     * \n     * @return void\n     */\n    private function __construct()\n    {\n        register_shutdown_function([$this, 'write']);\n    }\n\n    /**\n     * set log path function\n     * \n     * @return void\n     */\n    public function __set($name = '', $value = '')\n    {\n        if (! in_array($name, $this-\u003evariablesAllow)) {\n            throw new Exception('Operate is forbidden for this variable ' . $name, 401);    \n        }\n        $this-\u003e$name = $value;\n    }\n    \n    /**\n     * the magic function\n     * clone is forbidden\n     * \n     * @return string\n     */\n    public function __clone()\n    {\n        throw new Exception('Clone is forbidden', 401);\n    }\n  \n    /**\n     * get instance\n     * \n     * @return object\n     */\n    public static function getInstance()\n    {\n      if (!self::$_instance instanceof self) {\n        self::$_instance = new self;\n      }\n      return self::$_instance;\n    }\n\t\n\t/**\n\t * the magic __callStatics function\n\t *\n\t * @param string $method\n\t * @param array $log\n\t * @return void\n\t */\n\tpublic static function __callstatic($method = '', $log = [])\n\t{\n        $instance = self::getInstance();\n\t\tif (! in_array($method, $instance-\u003emethodSupport)) {\n\t\t\tthrow new Exception('log method not support', 500);\n\t\t}\n        $instance-\u003edecorate($method, $log);\n\t\t$instance-\u003epushLog();\n\t}\n\n\t/**\n\t * decorate log msg\n\t *\n\t * @param string $rank\n\t * @param array $log\n\t * @return void\n\t */\n\tprivate function decorate($rank = 'info', $log = [])\n\t{\n        if (! $log) {\n            $log = [];\n        }\n\t\t$time        = date('Y-m-d H: i: s', time());\n\t\t$pid         = posix_getpid();\n\t\t$memoryUsage = round(memory_get_usage()/1024, 2) . ' kb';\n\t\tswitch ($rank) {\n            case 'debug':\n                $rank = \"\\033[32m{$rank}\\033[0m\";\n            break;\n\t\t\tcase 'notice':\n\t\t\t\t$rank = \"\\033[36m{$rank} \\033[0m\";\n\t\t\tbreak;\n\t\t\tcase 'warning':\n\t\t\t\t$rank = \"\\033[33m{$rank}\\033[0m\";\n            break;\n            case 'error':\n                $rank = \"\\033[31m{$rank}\\033[0m\";\n            break;\n\t\t\t\n\t\t\tdefault:\n\t\t\t\n\t\t\tbreak;\n        }\n        \n\t\t$default = [\n\t\t\t$time,\n\t\t\t$rank,\n\t\t\t$pid,\n\t\t\t$memoryUsage\n        ];\n        \n        if ($log) {\n            foreach ($log as \u0026$v) {\n                if (is_array($v)) {\n                    if (defined('JSON_UNESCAPED_UNICODE')) {\n                        $v = json_encode($v, JSON_UNESCAPED_UNICODE);\n                    } else {\n                        $v = json_encode($v);\n                    }\n                }\n            }\n            unset($v);\n        }\n\n\t\t$log  = array_merge($default, $log);\n        $tmp  = '';\n\t\tforeach ($log as $k =\u003e $v) {\n\t\t\tif ($k === 0) {\n\t\t\t\t$tmp = \"{$v}\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t$tmp .= \" | {$v}\";\n        }\n        $this-\u003elog = $tmp;\n    }\n\n    /**\n     * the finally write\n     */\n    public function write()\n    {\n        if (! $this-\u003ebuffer) {\n            return;\n        }\n        $msg = '';\n        foreach ($this-\u003ebuffer as $v) {\n            $msg .= $v . PHP_EOL; \n        }\n\n        // check file path\n        if (! file_exists($this-\u003elogPath)) {\n            mkdir($this-\u003elogPath, 0777, true);\n        }\n        $this-\u003efinalFileName = $this-\u003elogPath . \"{$this-\u003elogFileName}.\" . date('Y-m-d', time()) . '.log';\n\n        // check file size\n        if (file_exists($this-\u003efinalFileName)) {\n            $filesize = filesize(realpath($this-\u003efinalFileName));\n            if ($filesize \u003e= $this-\u003elogFileSize*1024*1024) {\n                $this-\u003efinalFileName = $this-\u003elogPath . \"{$this-\u003elogFileName}.\" . date('Y-m-d', time());\n                $this-\u003efinalFileName .= '.' . date('H-i-s', time()) . '.log';\n            }\n        }\n            \n        // write\n        error_log(\n            $msg, \n            3, \n            $this-\u003efinalFileName\n        );\n    }\n\n    /**\n     * push the log msg to the buffer\n     */\n    public function pushLog()\n    {\n        $this-\u003ebuffer[] = $this-\u003elog;\n    }\n}\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasy-framework%2Feasy-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasy-framework%2Feasy-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasy-framework%2Feasy-log/lists"}