/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/utils/logger.vala

  • Committer: Gustav Hartvigsson
  • Date: 2024-12-21 22:39:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241221223917-jbt2ylyz9nxjss49
various changes
[utils/utils.vala]
* Removed uneeded int32_abs function

[utils/stack]
* more informative error when trying to pop an empty stack.

[utils/random.vala]
* added c_names to functions (probobly not needed).

[utils/pair.vala]
* Made compact
* made FreeFunc delegates unowned to fix error
* added constructor Pair.with_free_func ().

[utils/named_vector.vala]
* made class compact.

[utils/meson.build]
* Reordered files in list
* added logger.vala.

[utils/logger.vala]
* Added fast and easy logger class.

[utils/fast_number.vala]
* added a bunch of cname CCode attributes.

[general]
* Spelling in comments and functions.

[meson.build]
* Made dependancies easier to read
* added vala posix dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using Posix;
 
2
 
 
3
 
 
4
/*
 
5
 * Public Domain.
 
6
 */
 
7
[CCode (cname = "V", cprefix = "v_")]
 
8
namespace Utils {
 
9
  
 
10
  /**
 
11
   * This is a cheap logger, do not use for production code,
 
12
   * it is only for targets where GLib is not available.
 
13
   *
 
14
   * Use GLib's logging capabilities instead.
 
15
   */
 
16
  [CCode (cname = "VLogger", cprefix = "v_logger_")]
 
17
  public class Logger {
 
18
    private const string STR_ERROR = "[ERROR]: ";
 
19
    private const string STR_INFO = "[INFO]: ";
 
20
    private unowned FILE out_file;
 
21
    
 
22
    private static Logger logger = null;
 
23
    
 
24
    [CCode (cname = "v_logger_new")]
 
25
    public Logger (FILE out_file) {
 
26
      this.out_file = out_file;
 
27
    }
 
28
    
 
29
    [CCode (cname = "v_logger_get_default")]
 
30
    public static Logger get_default () {
 
31
      if (logger == null) {
 
32
         Logger.logger = new Logger (Posix.stdout);
 
33
      }
 
34
      return logger;
 
35
    }
 
36
    
 
37
    public static void set_default (Logger logger) {
 
38
      Logger.logger = logger;
 
39
    }
 
40
    
 
41
    [CCode (cname = "v_logger_err")]
 
42
    public void error (string str, ...) {
 
43
      out_file.printf (STR_ERROR);
 
44
      out_file.printf (str, va_list());
 
45
    }
 
46
    
 
47
    [CCode (cname = "v_logger_info")]
 
48
    public void info (string str, ...) {
 
49
      out_file.printf (STR_INFO);
 
50
      out_file.printf (str, va_list());
 
51
    }
 
52
    
 
53
    [CCode (cname = "v_logger_free_default")]
 
54
    public static void free_default () {
 
55
      Posix.free(Logger.logger);
 
56
    }
 
57
  }
 
58
}