{"id":21126011,"url":"https://github.com/julialogging/logcompose.jl","last_synced_at":"2026-01-02T05:27:56.761Z","repository":{"id":46227626,"uuid":"252345489","full_name":"JuliaLogging/LogCompose.jl","owner":"JuliaLogging","description":"Compose loggers and logger ensembles declaratively using configuration files.","archived":false,"fork":false,"pushed_at":"2023-10-12T17:28:46.000Z","size":28,"stargazers_count":5,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-21T12:17:28.740Z","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/JuliaLogging.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":"2020-04-02T03:24:59.000Z","updated_at":"2023-03-01T17:56:50.000Z","dependencies_parsed_at":"2022-09-19T07:31:23.338Z","dependency_job_id":null,"html_url":"https://github.com/JuliaLogging/LogCompose.jl","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaLogging%2FLogCompose.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaLogging%2FLogCompose.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaLogging%2FLogCompose.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaLogging%2FLogCompose.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaLogging","download_url":"https://codeload.github.com/JuliaLogging/LogCompose.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243573168,"owners_count":20312879,"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-11-20T04:38:45.279Z","updated_at":"2026-01-02T05:27:56.725Z","avatar_url":"https://github.com/JuliaLogging.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LogCompose\n\n[![Build Status](https://github.com/tanmaykm/LogCompose.jl/workflows/CI/badge.svg)](https://github.com/tanmaykm/LogCompose.jl/actions?query=workflow%3ACI+branch%3Amaster)\n[![Build Status](https://ci.appveyor.com/api/projects/status/github/tanmaykm/LogCompose.jl?branch=master\u0026svg=true)](https://ci.appveyor.com/project/tanmaykm/logroller-jl/branch/master)\n[![codecov.io](http://codecov.io/github/tanmaykm/LogCompose.jl/coverage.svg?branch=master)](http://codecov.io/github/tanmaykm/LogCompose.jl?branch=master)\n\nProvides a way to specify hierarchical logging configuration in a file.\n\nConfiguration file is in the form of a TOML file. Configuration sections are named,\nwith each section specifying a logger type and parameters needed for its construction.\nSections inherit parameter values from preceeding sections and can override them as well.\nLoggers can be constructed by providing the name of a section.\n\n[Here](example.toml) is what a configuration that allows logging to several types of loggers may look like.\n\n## Plugging in a Logger\n\nSupport for a logger can be added by providing an implementation of `LogCompose.logcompose` for the target logger type.\nThe implementation needs to be of the following form:\n\n```julia\nfunction LogCompose.logcompose(::Type{MyLoggerType},\n        config::Dict{String,Any},           # config: the entire logging configuration file\n        logger_config::Dict{String,Any})    # logger_config: configuration relevant for the\n                                            #      section specified to `LogCompose.logger`\n                                            #      with the hierarchy flattened out\n    # provides support for MyLoggerType in LogCompose\nend\n```\n\nFor complete examples, refer to any of the existing implementations listed below.\n\n## Loggers Supported\n\nLogCompose has in-built support for the loggers provided in the stdlib logging package.\nThey are listed below with example configuration sections illustrating parameters they accept.\n\n- Logging.SimpleLogger\n    ```\n    [loggers.simple]\n    type = \"Logging.SimpleLogger\"\n    # min_level = \"Debug\"             # Debug, Info (default) or Error\n    stream = \"simple.log\"             # file to log to\n    ```\n- Logging.ConsoleLogger\n    ```\n    [loggers.console]\n    type = \"Logging.ConsoleLogger\"\n    # min_level = \"Debug\"             # Debug, Info (default) or Error\n    stream = \"stdout\"                 # stdout (default), stderr or a filepath\n    ```\n- Logging.NullLogger\n    ```\n    [loggers.null]\n    type = \"Logging.NullLogger\"\n    ```\n\nThere are external packages that provide support for a few other types of loggers as well:\n\n- LoggingExtras: [LoggingExtrasCompose.jl](https://github.com/tanmaykm/LoggingExtrasCompose.jl)\n- LogRoller: [LogRollerCompose.jl](https://github.com/tanmaykm/LogRollerCompose.jl)\n- SyslogLogging: [SyslogLoggingCompose.jl](https://github.com/tanmaykm/SyslogLoggingCompose.jl)\n\nFor loggers supplied by external packages, LogCompose looks for the logger implementation type\n(the one mentioned in `type` configuration attribute) in the `Main` module by default. But if\nyour code imports the external loggers within your module instead of the Main module, then the\nmodule name where the logger type can be found must be specified in the (otherwise optional)\n`topmodule` configuration parameter. E.g.:\n\n```\n[loggers.rollinglog]\ntype = \"LogRoller.RollingFileLogger\"\ntopmodule = \"MyModule\"\n...\n```\n\n## Examples\n\nHere is an example configuration using multiple logger types, from different logging packages.\n\n```toml\n[file]\ntype = \"LogRoller.RollingLogger\"\nmin_level = \"Info\"\nnfiles = 5\n\n[syslog]\ntype = \"SyslogLogging.SyslogLogger\"\nfacility = \"user\"\n\n[file.testapp1]\nfilename = \"/tmp/testapp1.log\"\n\n[file.testapp2]\nfilename = \"/tmp/testapp2.log\"\nmin_level = \"Debug\"     # overrides min_level to Debug for testapp2\nnfiles = 10             # overrides nfiles to 10 for testapp2\n\n[syslog.testapp1]\nidentity = \"testapp1\"\nfacility = \"daemon\"     # facility set to daemon instead of default user\n\n[syslog.testapp2]\nidentity = \"testapp2\"\n\n[testapp1]\ntype = \"LoggingExtras.TeeLogger\"\ndestinations = [\"file.testapp1\", \"syslog.testapp1\"]\n\n[testapp2]\ntype = \"LoggingExtras.TeeLogger\"\ndestinations = [\"file.testapp2\", \"syslog.testapp2\"]\n```\n\nAnd below is a snippet of Julia code that make use of this configuration:\n\n```julia\njulia\u003e using LogCompose, Logging\n\njulia\u003e using LogRoller, LogRollerCompose\n\njulia\u003e using SyslogLogging, SyslogLoggingCompose\n\njulia\u003e using LoggingExtras, LoggingExtrasCompose\n\njulia\u003e logger1 = LogCompose.logger(\"testconfig.toml\", \"testapp1\");\n\njulia\u003e typeof(logger1)\nTeeLogger{Tuple{RollingLogger,SyslogLogger}}\n\njulia\u003e logger2 = LogCompose.logger(\"testconfig.toml\", \"testapp2\");\n\njulia\u003e typeof(logger2)\nTeeLogger{Tuple{RollingLogger,SyslogLogger}}\n\njulia\u003e first(logger1.loggers).stream.filename\n\"/tmp/testapp1.log\"\n\njulia\u003e first(logger2.loggers).stream.filename\n\"/tmp/testapp2.log\"\n\njulia\u003e first(logger2.loggers).stream.nfiles\n10\n\njulia\u003e with_logger(logger1) do\n           @info(\"hello from app1\")\n       end\n\nshell\u003e cat /tmp/testapp1.log\n┌ Info: 2020-04-02T12:03:03.588: hello from app1\n└ @ Main REPL[13]:2\n\njulia\u003e with_logger(logger2) do\n           @info(\"hello from app2\")\n       end\n\nshell\u003e cat /tmp/testapp2.log\n┌ Info: 2020-04-02T12:04:13.156: hello from app2\n└ @ Main REPL[15]:2\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulialogging%2Flogcompose.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulialogging%2Flogcompose.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulialogging%2Flogcompose.jl/lists"}