{"id":15647772,"url":"https://github.com/kmsquire/logging.jl","last_synced_at":"2025-10-23T23:24:26.088Z","repository":{"id":10549625,"uuid":"12748087","full_name":"kmsquire/Logging.jl","owner":"kmsquire","description":"Logging package for julia","archived":false,"fork":false,"pushed_at":"2017-08-05T05:25:05.000Z","size":57,"stargazers_count":43,"open_issues_count":21,"forks_count":26,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-20T04:36:23.286Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kmsquire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-11T05:09:43.000Z","updated_at":"2023-11-24T03:00:30.000Z","dependencies_parsed_at":"2022-09-18T19:00:41.206Z","dependency_job_id":null,"html_url":"https://github.com/kmsquire/Logging.jl","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmsquire%2FLogging.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmsquire%2FLogging.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmsquire%2FLogging.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmsquire%2FLogging.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kmsquire","download_url":"https://codeload.github.com/kmsquire/Logging.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430599,"owners_count":21429323,"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":[],"created_at":"2024-10-03T12:21:00.200Z","updated_at":"2025-10-23T23:24:25.996Z","avatar_url":"https://github.com/kmsquire.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"Logging.jl: Basic logging for Julia\n===================================\n\n[![PkgEval: Julia v0.4](http://pkg.julialang.org/badges/Logging_0.4.svg)](http://pkg.julialang.org/?pkg=Logging) \n[![PkgEval: Julia v0.5](http://pkg.julialang.org/badges/Logging_0.5.svg)](http://pkg.julialang.org/?pkg=Logging)\n[![PkgEval: Julia v0.6](http://pkg.julialang.org/badges/Logging_0.6.svg)](http://pkg.julialang.org/?pkg=Logging)\n\n[![TravisCI: Linux, OSX](https://travis-ci.org/kmsquire/Logging.jl.svg?branch=master)](https://travis-ci.org/kmsquire/Logging.jl)\n[![AppVeyorCI: Windows](https://ci.appveyor.com/api/projects/status/7cj5kaj8gcxmltho?svg=true)](https://ci.appveyor.com/project/kmsquire/logging-jl)\n\nThis module provides basic logging facilities for Julia.  It was inspired somewhat by logging in Python.\n\nInstall with `Pkg.add(\"Logging\")` at the Julia prompt.\n\nUsage\n-----\n\nIf `log_test.jl` contains\n\n```julia\nusing Logging\n# default:\n# Logging.configure(level=WARNING)\n\nfunction log_test()\n    debug(\"debug message\")\n    info(\"info message\")\n    warn(\"warning message\")\n    err(\"error message\")\n    critical(\"critical message\")\nend\n\nprintln(\"Setting level=DEBUG\")\nLogging.configure(level=DEBUG)\nlog_test()\n\nprintln()\nprintln(\"Setting level=INFO\")\nLogging.configure(level=INFO)\nlog_test()\n\nprintln()\nprintln(\"Setting level=WARNING\")\nLogging.configure(level=WARNING)\nlog_test()\n\nprintln()\nprintln(\"Setting level=ERROR\")\nLogging.configure(level=ERROR)\nlog_test()\n\nprintln()\nprintln(\"Setting level=CRITICAL\")\nLogging.configure(level=CRITICAL)\nlog_test()\n```\n\nRunning this gives\n\n```\njulia\u003e include(\"log_test.jl\")\nSetting level=DEBUG\n30-Oct 22:09:20:DEBUG:root:debug message\n30-Oct 22:09:20:INFO:root:info message\n30-Oct 22:09:20:WARNING:root:warning message\n30-Oct 22:09:20:ERROR:root:error message\n30-Oct 22:09:20:CRITICAL:root:critical message\n\nSetting level=INFO\n30-Oct 22:09:20:INFO:root:info message\n30-Oct 22:09:20:WARNING:root:warning message\n30-Oct 22:09:20:ERROR:root:error message\n30-Oct 22:09:20:CRITICAL:root:critical message\n\nSetting level=WARNING\n30-Oct 22:09:20:WARNING:root:warning message\n30-Oct 22:09:20:ERROR:root:error message\n30-Oct 22:09:20:CRITICAL:root:critical message\n\nSetting level=ERROR\n30-Oct 22:09:20:ERROR:root:error message\n30-Oct 22:09:20:CRITICAL:root:critical message\n\nSetting level=CRITICAL\n30-Oct 22:09:20:CRITICAL:root:critical message\n```\n\nAt the Julia prompt, the messages will display in color (debug=cyan,\ninfo=blue, warning=purple, error=red, critical=red).\n\nIt is possible to change the stream the logger prints to. For example,\nto print to a file:\n\n```julia\njulia\u003e Logging.configure(output=open(\"logfile.log\", \"a\"))\njulia\u003e log_test()\njulia\u003e readlines(open(\"logfile.log\"))\n3-element Array{Union(ASCIIString,UTF8String),1}:\n \"24-mar 18:40:24:WARNING:root:warning message\\n\"\n \"24-mar 18:40:24:ERROR:root:error message\\n\"\n \"24-mar 18:40:24:CRITICAL:root:critical message\\n\"\n```\n\nSince it is common to log to files, there is a shortcut:\n\n```julia\njulia\u003e Logging.configure(filename=\"logfile.log\")\n```\n\nLogging Macros\n--------------\n\nFor the functions above, there is always a small overhead for the\nfunction call even when there is no log output. Logging.jl provides\nmacros which work like the functions above, but which remove this\noverhead.\n\nTo use the macro versions, you MUST first configure them using\n`@Logging.configure`.\n\n```julia\nusing Logging\n@Logging.configure(level=DEBUG)\n\nfunction macro_log_test()\n    @debug(\"debug message\")\n    @info(\"info message\")\n    @warn(\"warning message\")\n    @err(\"error message\")\n    @critical(\"critical message\")\nend\n\nmacro_log_test()\n```\n\nThis gives:\n\n```julia\n30-Oct 22:28:51:DEBUG:root:debug message\n30-Oct 22:28:51:INFO:root:info message\n30-Oct 22:28:51:WARNING:root:warning message\n30-Oct 22:28:51:ERROR:root:error message\n30-Oct 22:28:51:CRITICAL:root:critical message\n```\n\nLater, we may decide to turn off logging entirely:\n\n```julia\nusing Logging\n@Logging.configure(level=OFF)\n\nfunction macro_log_test()\n    @debug(\"debug message\")\n    @info(\"info message\")\n    @warn(\"warning message\")\n    @err(\"error message\")\n    @critical(\"critical message\")\nend\n\nmacro_log_test()\n```\n\nThis prevents any of the logging code from being generated.\n\nNote that changing the log level later in the code will not have any\naffect on previously evaluated functions, though it does affect future\nevaluation:\n\n\n```julia\nusing Logging\nprintln(\"Setting level=OFF\")\n@Logging.configure(level=OFF)\n\nfunction macro_log_test()\n    # logging is OFF above!\n    # these messages will never produce output\n    # even if the log level is changed\n    @debug(\"debug message\")\n    @info(\"info message\")\n    @warn(\"warning message\")\n    @err(\"error message\")\n    @critical(\"critical message\")\nend\n\nmacro_log_test()\n\nprintln(\"Setting level=DEBUG\")\nLogging.configure(level=DEBUG)\nmacro_log_test()\n\n@warn(\"This warning message will print.\")\n@debug(\"So will this debug message!\")\n```\n\nproduces:\n\n```julia\nSetting level=OFF\nSetting level=DEBUG\n30-Oct 23:26:16:WARNING:root:This warning message will print.\n30-Oct 23:26:16:DEBUG:root:So will this debug message!\n```\n\nMore advanced usage\n-------------------\n\nIt is possible to create multiple loggers that each have their own log\nlevels and can write to different streams. A specific logger is used\nby giving it as the first argument to the logger functions or macros.\n\n```julia\njulia\u003e loggerA = Logger(\"loggerA\");\n\njulia\u003e Logging.configure(loggerA, level=ERROR);\n\njulia\u003e Logging.configure(loggerA, filename=\"loggerA.log\");\n\njulia\u003e loggerB = Logger(\"loggerB\");\n\njulia\u003e Logging.configure(loggerB, level=DEBUG);\n\njulia\u003e critical(loggerA, \"critical message from loggerA\");\n\njulia\u003e readlines(open(\"loggerA.log\"))\n1-element Array{Union(ASCIIString,UTF8String),1}:\n \"24-mar 18:48:23:CRITICAL:loggerA:critical message form loggerA\\n\"\n\njulia\u003e critical(loggerB, \"critical message from loggerB\");\n24-mar 18:49:15:CRITICAL:loggerB:critical message from loggerB\n```\n\nA logger can be created with a parent logger. A logger with a parent inherits\nthe configuration of the parent.\n\n```julia\njulia\u003e mum_logger = Logger(\"Mum\");\njulia\u003e Logging.configure(mum_logger, level=INFO);\njulia\u003e son_logger = Logger(\"Son\", parent=mum_logger);\njulia\u003e son_logger.level\nINFO\n```\n\nNotes\n-----\n* By default, `Logging.info` masks `Base.info`.  However, if `Base.info` is called before\n  `using Logging`, `info` will always refer to the `Base` version.\n\n```julia\njulia\u003e info(\"Here's some info.\")\nINFO: Here's some info.\n\njulia\u003e using Logging\nWarning: using Logging.info in module Main conflicts with an existing identifier.\n\njulia\u003e @Logging.configure(level=Logging.INFO)\nLogger(root,INFO,TTY(open, 0 bytes waiting),root)\n\njulia\u003e info(\"Still using Base.info\")\nINFO: Still using Base.info\n\njulia\u003e Logging.info(\"You can still fully qualify Logging.info.\")\n17-Jan 13:19:56:INFO:root:You can still fully qualify Logging.info.\n```\n\n  If this is not desirable, you may call `@Logging.configure` with `override_info=true`:\n\n```julia\njulia\u003e info(\"Here's some info again.\")\nINFO: Here's some info again.\n\njulia\u003e using Logging\nWarning: using Logging.info in module Main conflicts with an existing identifier.\n\njulia\u003e @Logging.configure(level=Logging.INFO, override_info=true)\nWarning: Method definition info(AbstractString...,) in module Base at util.jl:216 overwritten in module Main at /Users/kevin/.julia/v0.4/Logging/src/Logging.jl:85.\nLogger(root,INFO,TTY(open, 0 bytes waiting),root)\n\njulia\u003e info(\"Now we're using Logging.info\")\n17-Jan 13:17:20:INFO:root:Now we're using Logging.info\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmsquire%2Flogging.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkmsquire%2Flogging.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmsquire%2Flogging.jl/lists"}