120 lines
4.2 KiB
C
120 lines
4.2 KiB
C
|
|
// Software License Agreement (BSD License)
|
||
|
|
//
|
||
|
|
// Copyright (c) 2010-2023, Deusty, LLC
|
||
|
|
// All rights reserved.
|
||
|
|
//
|
||
|
|
// Redistribution and use of this software in source and binary forms,
|
||
|
|
// with or without modification, are permitted provided that the following conditions are met:
|
||
|
|
//
|
||
|
|
// * Redistributions of source code must retain the above copyright notice,
|
||
|
|
// this list of conditions and the following disclaimer.
|
||
|
|
//
|
||
|
|
// * Neither the name of Deusty nor the names of its contributors may be used
|
||
|
|
// to endorse or promote products derived from this software without specific
|
||
|
|
// prior written permission of Deusty, LLC.
|
||
|
|
|
||
|
|
// Disable legacy macros
|
||
|
|
#ifndef DD_LEGACY_MACROS
|
||
|
|
#define DD_LEGACY_MACROS 0
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#import "DDLog.h"
|
||
|
|
|
||
|
|
#define LOG_CONTEXT_ALL INT_MAX
|
||
|
|
|
||
|
|
#pragma clang diagnostic push
|
||
|
|
#pragma clang diagnostic ignored "-Wunused-function"
|
||
|
|
#if !(TARGET_OS_OSX)
|
||
|
|
// iOS or tvOS or watchOS
|
||
|
|
#import <UIKit/UIColor.h>
|
||
|
|
typedef UIColor DDColor;
|
||
|
|
static inline DDColor* _Nonnull DDMakeColor(CGFloat r, CGFloat g, CGFloat b) {return [DDColor colorWithRed:(r/(CGFloat)255.0) green:(g/(CGFloat)255.0) blue:(b/(CGFloat)255.0) alpha:1.0];}
|
||
|
|
#elif defined(DD_CLI) || !__has_include(<AppKit/NSColor.h>)
|
||
|
|
// OS X CLI
|
||
|
|
#import <CocoaLumberjack/CLIColor.h>
|
||
|
|
typedef CLIColor DDColor;
|
||
|
|
static inline DDColor* _Nonnull DDMakeColor(CGFloat r, CGFloat g, CGFloat b) {return [DDColor colorWithCalibratedRed:(r/255.0) green:(g/255.0) blue:(b/255.0) alpha:1.0];}
|
||
|
|
#else
|
||
|
|
// OS X with AppKit
|
||
|
|
#import <AppKit/NSColor.h>
|
||
|
|
typedef NSColor DDColor;
|
||
|
|
static inline DDColor * _Nonnull DDMakeColor(CGFloat r, CGFloat g, CGFloat b) {return [DDColor colorWithCalibratedRed:(r/255.0) green:(g/255.0) blue:(b/255.0) alpha:1.0];}
|
||
|
|
#endif
|
||
|
|
#pragma clang diagnostic pop
|
||
|
|
|
||
|
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This class provides a logger for Terminal output or Xcode console output,
|
||
|
|
* depending on where you are running your code.
|
||
|
|
*
|
||
|
|
* As described in the "Getting Started" page,
|
||
|
|
* the traditional NSLog() function directs it's output to two places:
|
||
|
|
*
|
||
|
|
* - Apple System Log (so it shows up in Console.app)
|
||
|
|
* - StdErr (if stderr is a TTY, so log statements show up in Xcode console)
|
||
|
|
*
|
||
|
|
* To duplicate NSLog() functionality you can simply add this logger and an asl logger.
|
||
|
|
* However, if you instead choose to use file logging (for faster performance),
|
||
|
|
* you may choose to use only a file logger and a tty logger.
|
||
|
|
**/
|
||
|
|
@interface DDTTYLogger : NSObject///DDAbstractLogger <DDLogger>
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Singleton instance. Returns `nil` if the initialization of the DDTTYLogger fails.
|
||
|
|
*/
|
||
|
|
@property (nonatomic, class, readonly, strong, nullable) DDTTYLogger *sharedInstance;
|
||
|
|
|
||
|
|
/* Inherited from the DDLogger protocol:
|
||
|
|
*
|
||
|
|
* Formatters may optionally be added to any logger.
|
||
|
|
*
|
||
|
|
* If no formatter is set, the logger simply logs the message as it is given in logMessage,
|
||
|
|
* or it may use its own built in formatting style.
|
||
|
|
*
|
||
|
|
* More information about formatters can be found here:
|
||
|
|
* Documentation/CustomFormatters.md
|
||
|
|
*
|
||
|
|
* The actual implementation of these methods is inherited from DDAbstractLogger.
|
||
|
|
|
||
|
|
- (id <DDLogFormatter>)logFormatter;
|
||
|
|
- (void)setLogFormatter:(id <DDLogFormatter>)formatter;
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Want to use different colors for different log levels?
|
||
|
|
* Enable this property.
|
||
|
|
*
|
||
|
|
* If you run the application via the Terminal (not Xcode),
|
||
|
|
* the logger will map colors to xterm-256color or xterm-color (if available).
|
||
|
|
*
|
||
|
|
* Xcode does NOT natively support colors in the Xcode debugging console.
|
||
|
|
* You'll need to install the XcodeColors plugin to see colors in the Xcode console.
|
||
|
|
* https://github.com/robbiehanson/XcodeColors
|
||
|
|
*
|
||
|
|
* The default value is NO.
|
||
|
|
**/
|
||
|
|
@property (readwrite, assign) BOOL colorsEnabled;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* When using a custom formatter you can set the `logMessage` method not to append
|
||
|
|
* `\n` character after each output. This allows for some greater flexibility with
|
||
|
|
* custom formatters. Default value is YES.
|
||
|
|
**/
|
||
|
|
@property (nonatomic, readwrite, assign) BOOL automaticallyAppendNewlineForCustomFormatters;
|
||
|
|
|
||
|
|
/**
|
||
|
|
Using this initializer is not supported. Please use `DDTTYLogger.sharedInstance`.
|
||
|
|
**/
|
||
|
|
- (instancetype)init NS_UNAVAILABLE;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
- (void)logMessage:(DDLogMessage *)logMessage;
|
||
|
|
@property(nonatomic,strong,readonly)NSMutableArray * colorProfilesArray;
|
||
|
|
@end
|
||
|
|
|
||
|
|
|
||
|
|
NS_ASSUME_NONNULL_END
|