{"id":20037979,"url":"https://github.com/perfectlysoft/perfect-logger","last_synced_at":"2025-08-17T14:06:27.379Z","repository":{"id":63920164,"uuid":"73886766","full_name":"PerfectlySoft/Perfect-Logger","owner":"PerfectlySoft","description":"File-Based Logging.","archived":false,"fork":false,"pushed_at":"2020-07-18T17:49:17.000Z","size":38,"stargazers_count":19,"open_issues_count":1,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-29T02:48:00.998Z","etag":null,"topics":["logging","perfect","server-side-swift","swift"],"latest_commit_sha":null,"homepage":"https://www.perfect.org","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerfectlySoft.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":"2016-11-16T05:18:58.000Z","updated_at":"2022-10-28T08:42:36.000Z","dependencies_parsed_at":"2023-01-14T14:00:32.795Z","dependency_job_id":null,"html_url":"https://github.com/PerfectlySoft/Perfect-Logger","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/PerfectlySoft/Perfect-Logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-Logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-Logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-Logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-Logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerfectlySoft","download_url":"https://codeload.github.com/PerfectlySoft/Perfect-Logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-Logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270856775,"owners_count":24657700,"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-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["logging","perfect","server-side-swift","swift"],"created_at":"2024-11-13T10:24:29.582Z","updated_at":"2025-08-17T14:06:27.326Z","avatar_url":"https://github.com/PerfectlySoft.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perfect Logging (File \u0026 Remote)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://perfect.org/get-involved.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.org/assets/github/perfect_github_2_0_0.jpg\" alt=\"Get Involed with Perfect!\" width=\"854\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PerfectlySoft/Perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_1_Star.jpg\" alt=\"Star Perfect On Github\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://stackoverflow.com/questions/tagged/perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/perfect_gh_button_2_SO.jpg\" alt=\"Stack Overflow\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"https://twitter.com/perfectlysoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_3_twit.jpg\" alt=\"Follow Perfect on Twitter\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_4_slack.jpg\" alt=\"Join the Perfect Slack\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat\" alt=\"Swift 3.0\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-lightgray.svg?style=flat\" alt=\"Platforms OS X | Linux\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.org/licensing.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat\" alt=\"License Apache\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://twitter.com/PerfectlySoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Twitter-@PerfectlySoft-blue.svg?style=flat\" alt=\"PerfectlySoft Twitter\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.ly/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nUsing the `PerfectLogger` module, events can be logged to a specfied file, in addition to the console.\n\nSupport is also included in this module for remote logging events to the [Perfect Log Server](https://github.com/PerfectServers/Perfect-LogServer).\n\n## Using in your project\n\nAdd the dependancy to your project's Package.swift file:\n\n``` swift\n.Package(url: \"https://github.com/PerfectlySoft/Perfect-Logger.git\", majorVersion: 3),\n```\n\nNow add the `import` directive to the file you wish to use the logging in:\n\n``` swift\nimport PerfectLogger\n```\n\nTo log events to the local console as well as a file:\n\n``` swift\nLogFile.debug(\"debug message\", logFile: \"test.txt\")\nLogFile.info(\"info message\", logFile: \"test.txt\")\nLogFile.warning(\"warning message\", logFile: \"test.txt\")\nLogFile.error(\"error message\", logFile: \"test.txt\")\nLogFile.critical(\"critical message\", logFile: \"test.txt\")\nLogFile.terminal(\"terminal message\", logFile: \"test.txt\")\n```\n\nTo log to the default file, omit the file name parameter.\n\n## Linking events with \"eventid\"\n\nEach log event returns an event id string. If an eventid string is supplied to the directive then it will use the supplied eventid in the log file instead - this makes it easy to link together related events.\n\n``` swift\nlet eid = LogFile.warning(\"test 1\")\nLogFile.critical(\"test 2\", eventid: eid)\n```\n\nreturns:\n\n```\n[WARNING] [62f940aa-f204-43ed-9934-166896eda21c] [2016-11-16 15:18:02 GMT-05:00] test 1\n[CRITICAL] [62f940aa-f204-43ed-9934-166896eda21c] [2016-11-16 15:18:02 GMT-05:00] test 2\n```\n\nThe returned eventid is marked `@discardableResult` therefore can be safely ignored if not required for re-use.\n\n\n## Customization\n\n### Setting a custom Logfile location\n\nThe default logfile location is `./log.log`. To set a custom logfile location, set the `LogFile.location` variable:\n\n``` swift\nLogFile.location = \"/var/log/myLog.log\"\n```\n\nMessages can now be logged directly to the file as set by using:\n\n``` swift\nLogFile.debug(\"debug message\")\nLogFile.info(\"info message\")\nLogFile.warning(\"warning message\")\nLogFile.error(\"error message\")\nLogFile.critical(\"critical message\")\nLogFile.terminal(\"terminal message\")\n```\n\n### LogFile threshold\n\nFor debug purposes, you want to see as much info as available. However, on production servers you probably desire a\nsmaller logfile and filter out all redundant info.\n\nTo do so, you may set the LogFile's `threshold` property to the minumum priority you want to actually being logged into the file.\n\ne.g.:\n\n```swift\nLogFile.threshold = .warning\nLogFile.debug(\"This won't be logged into the file\")\nLogFile.info(\"This won't be logged into the file\")\nLogFile.warning(\"This will be logged into the file\")\nLogFile.error(\"This will be logged into the file\")\nLogFile.critical(\"This will be logged into the file\")\n```\n\nThe default value of this property is `.debug` to preserve backward compatibility and this property will not affect the Console/Remote logger.\n\n### LogFile options\n\nDepending on your needs, you may not be interested in an event id, timestamp or priority.\n\nUsing the LogFile's `options` property you can customize which of those fields will actually be added as a prefix to the log message.\n\ne.g.:\n\n```swift\n// Default behaviour (equal to `[.priority, .eventId, .timestamp]`)\nLogFile.options = .default\nLogFile.debug(\"This is my log message\")\n// Will log: \"[DEBUG] [CEC5B5DB-931F-4C5A-A794-17D060BABC80] [2019-05-04 15:16:11 GMT+02:00] This is my log message\"\n\nLogFile.options = .none\nLogFile.debug(\"This is my log message\")\n// Will log: \"This is my log message\"\n\nLogFile.options = [.priority, .timestamp]\nLogFile.debug(\"This is my log message\")\n// Will log: \"[DEBUG] [2019-05-04 15:16:11 GMT+02:00] This is my log message\"\n\nLogFile.options = [.priority]\nLogFile.debug(\"This is my log message\")\n// Will log: \"[DEBUG] This is my log message\"\n```\n\n\n## Sample output\n\n```\n[DEBUG] [ec6a9ca5-00b1-4656-9e4c-ddecae8dde02] [2016-11-16 15:18:02 GMT-05:00] a debug message\n[INFO] [ec6a9ca5-00b1-4656-9e4c-ddecae8dde02] [2016-11-16 15:18:02 GMT-05:00] an informational message\n[WARNING] [ec6a9ca5-00b1-4656-9e4c-ddecae8dde02] [2016-11-16 15:18:02 GMT-05:00] a warning message\n[ERROR] [62f940aa-f204-43ed-9934-166896eda21c] [2016-11-16 15:18:02 GMT-05:00] an error message\n[CRITICAL] [62f940aa-f204-43ed-9934-166896eda21c] [2016-11-16 15:18:02 GMT-05:00] a critical message\n[EMERG] [ec6a9ca5-00b1-4656-9e4c-ddecae8dde02] [2016-11-16 15:18:02 GMT-05:00] an emergency message\n```\n\n## Remote Logging\n\nThe \"Perfect-Logging\" dependency includes support for remote logging to this log server.\n\nTo include the dependency in your project, add the following to your project's Package.swift file:\n\n``` swift\n.Package(url: \"https://github.com/PerfectlySoft/Perfect-Logger.git\", majorVersion: 3),\n```\n\nNow add the import directive to the file you wish to use the logging in:\n\n``` swift \nimport PerfectLogger\n```\n\n#### Configuration\nThree configuration parameters are required:\n\n``` swift\n// Your token\nRemoteLogger.token = \"\u003cyour token\u003e\"\n\n// App ID (Optional)\nRemoteLogger.appid = \"\u003cyour appid\u003e\"\n\n// URL to access the log server. \n// Note, this is not the full API path, just the host and port.\nRemoteLogger.logServer = \"http://localhost:8181\"\n\n```\n\n\n#### To log events to the log server:\n\n``` swift\nvar obj = [String: Any]()\nobj[\"one\"] = \"donkey\"\nRemoteLogger.critical(obj)\n```\n\n#### Linking events with \"eventid\"\n\nEach log event returns an event id string. If an eventid string is supplied to the directive then it will use the supplied eventid in the log directive instead - this makes it easy to link together related events.\n\n``` swift\nlet eid = RemoteLogger.critical(obj)\nRemoteLogger.info(obj, eventid: eid)\n```\n\nThe returned eventid is marked @discardableResult therefore can be safely ignored if not required for re-use.\n\n## Further Information\nFor more information on the Perfect project, please visit [perfect.org](http://perfect.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperfectlysoft%2Fperfect-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-logger/lists"}