Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding log handler in hs.logger. Add option to log to file. #2627

Closed
wants to merge 2 commits into from

Conversation

gineer01
Copy link

PR for #1684

Allow overriding log handler in hs.logger with hs.logger.logHandler().
User can use hs.logger.createFileLogHandler(path) to create a log handler that logs to a file at the provided path.
Refactor the current handling to the constant logger.defaultLogHandler and use it as the default value for logHandler.

Some example code (also in the function documentation):

local fileHandler = hs.logger.createFileLogHandler('path/example.log')
hs.logger.logHandler(function(log)
   fileHandler(log)
   hs.logger.defaultLogHandler(log)
end)

Refactor the current handling to the constant logger.defaultLogHandler and use it as the default value for logHandler
--- However, this will log only to the file, leaving the console empty. If you want
--- to log to both file and console, you can create a new log handler that calls
--- both the file log handler and hs.logger.defaultLogHandler
---

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(W614) trailing whitespace in a comment

@codecov
Copy link

codecov bot commented Dec 20, 2020

Codecov Report

Merging #2627 (c924260) into master (5ba3efa) will decrease coverage by 19.60%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #2627       +/-   ##
==========================================
- Coverage   27.07%   7.47%   -19.61%     
==========================================
  Files         177       3      -174     
  Lines       35301    1258    -34043     
==========================================
- Hits         9557      94     -9463     
+ Misses      25744    1164    -24580     

@muescha
Copy link
Contributor

muescha commented May 22, 2023

should names be ConsoleLogHandler and FileLogHandler?

or better as objects ConsoleLogger and FileLogger where we have :init and :log method?

@cmsj
Copy link
Member

cmsj commented Dec 10, 2023

Since this has gotten stale and has a merge conflict, I'm going to close it for now. Please feel free to re-open (or open a new PR) if you're able to resolve the conflicts.

@cmsj cmsj closed this Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants