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

OSLogWriter sends os logs with same type for both warn and error levels #45

Closed
MarcoFilosi opened this issue Sep 26, 2018 · 9 comments
Closed

Comments

@MarcoFilosi
Copy link

It seems OSLogWriter sends os logs with type error for both warn and error levels.
I think it would be better to have different types for these 2 levels assigning fault type to error level.

In LogWriter.swift at line 186 (on master branch) we have:

        case LogLevel.warn:  return .error
        case LogLevel.error: return .error

we could just modify it in this way:

        case LogLevel.warn:  return .error
        case LogLevel.error: return .fault
@cnoon
Copy link
Member

cnoon commented Oct 10, 2018

Hi @MarcoFilosi,

Thanks for putting this ticket together. After more investigation, I tend to agree with you that that change is warranted. I'm assuming that we went with .error mapping across the Willow .warn and .error log levels because of the description of the os_log .fault level.

I honestly can't remember making a conscious decision to go with .error for both log levels, but I would guess that I did.

However, reading through it again, it doesn't really seem to me that .fault should be avoided, and certainly falls more inline with Willow's concept of .error.

os_log

Docs can be found here.

Error

Error-level messages are always saved in the data store. They remain there until a storage quota is exceeded, at which point, the oldest messages are purged. Error-level messages are intended for reporting process-level errors. If an activity object exists, logging at this level captures information for the entire process chain.

Fault

Fault-level messages are always saved in the data store. They remain there until a storage quota is exceeded, at which point, the oldest messages are purged. Fault-level messages are intended for capturing system-level or multi-process errors only. If an activity object exists, logging at this level captures information for the entire process chain.


I'm really curious to get your thoughts as well @ejensen.

If @ejensen agrees @MarcoFilosi, would you mind putting together a PR with the fix?

@ejensen
Copy link
Contributor

ejensen commented Oct 10, 2018

If I remember correctly the reason .fault was avoided was because of this description from OSLogType.fault:

Use this level to capture system-level or multi-process information to report system errors.

The "system-level or multi-process information" is not the typical case of an error log.

I don't feel strongly about avoiding .fault, but another option for using a different levels for error and warn is to switch warn to the OSLogType.default:

Use this level to capture information about things that might result a failure.

@cnoon
Copy link
Member

cnoon commented Oct 11, 2018

Both good points @ejensen.

I also believe that's why we steered clear of OSLogType.fault originally. I also agree that Willow's LogLevel..warn log level does fall more inline with OSLogType.default. Would it make the most sense to switch LogLevel.warn = OSLogType.default and require a custom log level to explicitly use the OSLogType.fault level?

I wish we could have the following, but I don't think they map correctly given the Apple docs:

LogLevel.event = OSLogType.default
LogLevel.warn = OSLogType.error
LogLevel.error = OSLogType.fault

I think instead it probably makes the most sense to do the following (as you pointed out):

LogLevel.event = OSLogType.default
LogLevel.warn = OSLogType.default
LogLevel.error = OSLogType.error

You could always still use .fault in a couple different ways.

  1. You could re-create the OSLogWriter functionality with different functionality. It's a really simple class.
  2. We could make the logType(forLogLevel:) API open so you could subclass and override only that API.

Thoughts @ejensen and @MarcoFilosi?

@ejensen
Copy link
Contributor

ejensen commented Oct 12, 2018

Firstly, I like the flexibility of the open func logType(forLogLevel:) idea, regardless of what we decide to set as the default log level.

I’m leaning towards LogLevel.warn = OSLogType.default

@cnoon
Copy link
Member

cnoon commented Oct 14, 2018

@MarcoFilosi would you be willing to put this PR together?

@cnoon
Copy link
Member

cnoon commented Jan 3, 2019

Ping here @MarcoFilosi...would you be willing to put this PR together?

@AnthonyMillerSF
Copy link

I agree that default is the right default logging level for LogLevel.warn. Any chance this PR is coming soon?

@ejensen
Copy link
Contributor

ejensen commented Apr 27, 2019

I recently posted PR #53 to both make the logType(forLogLevel:) open, and map LogLevel.warn to OSLogType.default

@cnoon cnoon added this to the 5.2.0 milestone Apr 30, 2019
@cnoon
Copy link
Member

cnoon commented Apr 30, 2019

Closing this issue out since it was resolved in #53. Thanks again @ejensen!

@cnoon cnoon closed this as completed Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants