source: launchers/macosx/I2PLauncher/logger_c.h @ 36b758f

Last change on this file since 36b758f was e8d371e, checked in by meeh <meeh@…>, 2 years ago

Mac OSX Launcher: C api of the logger to become available for Swift/Objective?-C

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2//  logger_c.h
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 30/09/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9#ifndef logger_c_h
10#define logger_c_h
11
12#include "Logger.h"
13#include "LoggerWorker.hpp"
14
15/*
16void genericLogger(int loglevel, va_list params) {
17#ifdef __cplusplus
18  const char * paramArray[10];
19  int numParams = 0;
20 
21  NSString* arg = nil;
22  while ((arg = va_arg(params, NSString *))) {
23    paramArray[numParams++] = [arg cStringUsingEncoding:[NSString defaultCStringEncoding]];
24  }
25 
26  switch (loglevel) {
27    case 0:
28      MLOGF(ANNOYING) << params;
29      break;
30    case 1:
31      MLOGF(DEBUG) << params;
32      break;
33    case 2:
34      MLOGF(INFO) << params;
35      break;
36    case 3:
37      MLOGF(WARN) << params;
38      break;
39    default:
40      assert(false);
41  }
42#endif
43}
44 */
45
46void MLog(int loglevel, NSString* format, ...)
47{
48#ifdef __cplusplus
49  static NSDateFormatter* timeStampFormat;
50  if (!timeStampFormat) {
51    timeStampFormat = [[NSDateFormatter alloc] init];
52    [timeStampFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
53    [timeStampFormat setTimeZone:[NSTimeZone systemTimeZone]];
54  }
55 
56  NSString* timestamp = [timeStampFormat stringFromDate:[NSDate date]];
57 
58  va_list vargs;
59  va_start(vargs, format);
60  NSString* formattedMessage = [[NSString alloc] initWithFormat:format arguments:vargs];
61  va_end(vargs);
62 
63  NSString* message = [NSString stringWithFormat:@"<%@> %@", timestamp, formattedMessage];
64 
65  switch (loglevel) {
66    case 0:
67      MLOGF(ANNOYING) << message;
68      break;
69    case 1:
70      MLOGF(DEBUG) << message;
71      break;
72    case 2:
73      MLOGF(INFO) << message;
74      break;
75    case 3:
76      MLOGF(WARN) << message;
77      break;
78    case 4:
79      MLOGF(ERROR) << message;
80      break;
81    default:
82#if DEBUG
83      assert(false);
84#endif
85  }
86 
87#endif
88}
89
90
91#endif /* logger_c_h */
Note: See TracBrowser for help on using the repository browser.