forked from b4winckler/macvim
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1 extracted log macros and custom key binding init code
- Loading branch information
Tae Won Ha
committed
May 25, 2013
1 parent
756a367
commit a078663
Showing
8 changed files
with
169 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* vi:set ts=8 sts=4 sw=4 ft=objc: | ||
* | ||
* VIM - Vi IMproved by Bram Moolenaar | ||
* MacVim GUI port by Bjorn Winckler | ||
* | ||
* Do ":help uganda" in Vim to read copying and usage conditions. | ||
* Do ":help credits" in Vim to see a list of people who contributed. | ||
* See README.txt for an overview of the Vim source code. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <asl.h> | ||
|
||
// Logging related functions and macros. | ||
// | ||
// This is a very simplistic logging facility built on top of ASL. Two user | ||
// defaults allow for changing the local log filter level (MMLogLevel) and | ||
// whether logs should be sent to stderr (MMLogToStdErr). (These user defaults | ||
// are only checked during startup.) The default is to block level 6 (info) | ||
// and 7 (debug) logs and _not_ to send logs to stderr. Apart from this | ||
// "syslog" (see "man syslog") can be used to modify the ASL filters (it is | ||
// currently not possible to change the local filter at runtime). For example: | ||
// Enable all logs to reach the ASL database (by default 'debug' and 'info' | ||
// are filtered out, see "man syslogd"): | ||
// $ sudo syslog -c syslogd -d | ||
// Reset the ASL database filter: | ||
// $ sudo syslog -c syslogd off | ||
// Change the master filter to block logs less severe than errors: | ||
// $ sudo syslog -c 0 -e | ||
// Change per-process filter for running MacVim process to block logs less | ||
// severe than warnings: | ||
// $ syslog -c MacVim -w | ||
// | ||
// Note that there are four ASL filters: | ||
// 1) The ASL database filter (syslog -c syslogd ...) | ||
// 2) The master filter (syslog -c 0 ...) | ||
// 3) The per-process filter (syslog -c PID ...) | ||
// 4) The local filter (MMLogLevel) | ||
// | ||
// To view the logs, either use "Console.app" or the "syslog" command: | ||
// $ syslog -w | grep Vim | ||
// To get the logs to show up in Xcode enable the MMLogToStdErr user default. | ||
|
||
extern NSString *MMLogLevelKey; | ||
extern NSString *MMLogToStdErrKey; | ||
|
||
extern int ASLogLevel; | ||
|
||
void ASLInit(); | ||
|
||
#define ASLog(level, fmt, ...) \ | ||
if (level <= ASLogLevel) { \ | ||
asl_log(NULL, NULL, level, "%s@%d: %s", \ | ||
__PRETTY_FUNCTION__, __LINE__, \ | ||
[[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \ | ||
} | ||
|
||
// Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C | ||
// style specifiers (%@) are supported. | ||
#define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__) | ||
#define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__) | ||
#define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__) | ||
#define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__) | ||
#define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__) | ||
#define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__) | ||
#define ASLogTmp(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* vi:set ts=8 sts=4 sw=4 ft=objc: | ||
* | ||
* VIM - Vi IMproved by Bram Moolenaar | ||
* MacVim GUI port by Bjorn Winckler | ||
* | ||
* Do ":help uganda" in Vim to read copying and usage conditions. | ||
* Do ":help credits" in Vim to see a list of people who contributed. | ||
* See README.txt for an overview of the Vim source code. | ||
*/ | ||
|
||
#import "MMLog.h" | ||
|
||
NSString *MMLogLevelKey = @"MMLogLevel"; | ||
NSString *MMLogToStdErrKey = @"MMLogToStdErr"; | ||
|
||
void | ||
ASLInit() | ||
{ | ||
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; | ||
|
||
// Allow for changing the log level via user defaults. If no key is found | ||
// the default log level will be used (which for ASL is to log everything | ||
// up to ASL_LEVEL_NOTICE). This key is an integer which corresponds to | ||
// the ASL_LEVEL_* macros (0 is most severe, 7 is debug level). | ||
id logLevelObj = [ud objectForKey:MMLogLevelKey]; | ||
if (logLevelObj) { | ||
int logLevel = [logLevelObj intValue]; | ||
if (logLevel < 0) logLevel = 0; | ||
if (logLevel > ASL_LEVEL_DEBUG) logLevel = ASL_LEVEL_DEBUG; | ||
|
||
ASLogLevel = logLevel; | ||
asl_set_filter(NULL, ASL_FILTER_MASK_UPTO(logLevel)); | ||
} | ||
|
||
// Allow for changing whether a copy of each log should be sent to stderr | ||
// (this defaults to NO if this key is missing in the user defaults | ||
// database). The above filter mask is applied to logs going to stderr, | ||
// contrary to how "vanilla" ASL works. | ||
BOOL logToStdErr = [ud boolForKey:MMLogToStdErrKey]; | ||
if (logToStdErr) | ||
asl_add_log_file(NULL, 2); // The file descriptor for stderr is 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters