{"id":15722679,"url":"https://github.com/subsoap/log","last_synced_at":"2025-06-16T19:06:03.633Z","repository":{"id":39610612,"uuid":"136995071","full_name":"subsoap/log","owner":"subsoap","description":"General purpose logging for Defold","archived":false,"fork":false,"pushed_at":"2022-05-31T05:02:54.000Z","size":41,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-16T13:16:07.713Z","etag":null,"topics":["defold","defold-game-engine"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/subsoap.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":"2018-06-12T00:17:46.000Z","updated_at":"2024-09-13T09:38:24.000Z","dependencies_parsed_at":"2022-09-15T21:40:59.339Z","dependency_job_id":null,"html_url":"https://github.com/subsoap/log","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/subsoap/log","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subsoap%2Flog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subsoap%2Flog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subsoap%2Flog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subsoap%2Flog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/subsoap","download_url":"https://codeload.github.com/subsoap/log/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/subsoap%2Flog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260221329,"owners_count":22976859,"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":["defold","defold-game-engine"],"created_at":"2024-10-03T22:08:52.505Z","updated_at":"2025-06-16T19:06:03.574Z","avatar_url":"https://github.com/subsoap.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":["Programming Language"],"readme":"# Log\nGeneral purpose logging for Defold\n\n## Installation\nYou can use Log in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add:\n\n\thttps://github.com/subsoap/log/archive/master.zip\n  \nOnce added, you must require the main Lua module in your scripts via\n\n```\nlocal log = require(\"log.log\")\n```\n\nOr require it globally in your main entrypoint so that all of your scripts can use Log without each needing to require it.\n\n```\nlog = require(\"log.log\")\n```\n\nThere is an optional dependency for LFS which is currently required if you would like to be able to auto-prune old log files. LFS is a native extension so could add to build time if you are not already using a native extension. This can be ignored if you don't care about auto-pruning of old log files.\n\n\thttps://github.com/britzl/defold-lfs\n\n\thttps://github.com/britzl/defold-lfs/archive/master.zip\n\n## Usage\n\nIf you wish to have log lines be printed to the Defold console you must toggle console printing in your main file. Otherwise log lines will only be added to the log files.\n\n```\nlog.toggle_print()\n```\n\nFirst set your appname. Your appname determines a relative OS directory for storing your app's logs.\n\n```\nlog.set_appname(\"YourAppName\")\n```\n\nYou can then log information to logs based on levels. You can use a short or long form of the log function names.\n\n```\nlog.c(\"This would be a critical log message.\")\nlog.critical(\"This would also be a critical log message.\")\n```\n\nHere is what the above lines would log to your log file. Note that it inclues the log level, timestamp, and script information (path and line number) of which script did the logging.\n\n```\n[CRIT  2018-06-12 00:21:10] /example/example.script:19: This would be a critical log message.\n[CRIT  2018-06-12 00:21:10] /example/example.script:20: This would also be a critical log message.\n```\n\nThere are muliple built in log levels. You are able to set the minimum log level so that any messages below that log level are not logged.\n\n```\nlog.set_level(log.INFO) -- disable logging for all log levels below log.INFO\n```\n\nThe available builtin log levels are from lowest to highest:\n\n```\nlog.t(message, tag)\nlog.trace(message, tag)\nlog.TRACE = 10\n\nlog.d(message, tag)\nlog.debug(message, tag)\nlog.DEBUG = 20\n\nlog.i(message, tag)\nlog.info(message, tag)\nlog.INFO = 30\n\nlog.w(message, tag)\nlog.warning(message, tag)\nlog.WARNING = 40\n\nlog.e(message, tag)\nlog.error(message, tag)\nlog.ERROR = 50\n\nlog.c(message, tag)\nlog.critical(message, tag)\nlog.CRITICAL = 60\n```\n\nIf you save a log line directly without using a log level function you can manually specifiy the log level. The debug_level should be left to be nil or 0 if log.save_log_line is called directly.\n\n```\nlog.save_log_line(line, level, tag, debug_level)\n```\n\nWhen you log a message you can include an optional tag. Tags can be used to whitelist (or blacklist) certain log information types. For example, you may only want to allow logging from one section of your game while you are doing debugging, you can disable all other log tags.\n\nTo enable the tag whitelist and add a tag to the whitelist use\n\n```\nlog.use_tag_whitelist = false\nlog.add_to_whitelist(tag, state)\n```\n\nYou can also modify the table holding the whitelist data directly.\n\n```\nlog.tag_whitelist = \n{\n\t[\"none\"] = false,\n\t[\"msg_proxy\"] = true\n}\n```\n\nBy default, all logging is disabled when you bundle a release build. To force logging to continue in release builds then you must set this value to false\n\n```\nlog.disable_logging_for_release = false\n```\n\nBy default, dates are used for log filenames. If you wish to store logs within a single file then disable using dates for filenames.\n\n```\nlog.use_date_for_filename = false\n```\n\nYou can change the default dateless log filename too.\n\n```\nlog.logging_filename = \"app.log\"\n```\n\nYou can manually disable all logging with\n\n```\nlog.logging = false\n```\n\nYou can delete old log files (such as on the init of your main entrypoint) based on the number of days you wish to keep logs around. This requires the LFS extension to be included (for now). This function will only delete logs which match the pattern of NNNN-NN-NN.log or it will not delete. If you don't set the number of days then it will default to log.delete_old_logs_days which by default is 10 days.\n\n```\nlog.delete_old_logs(days)\n```\n\n![Log](log_logo.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubsoap%2Flog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsubsoap%2Flog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsubsoap%2Flog/lists"}