/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/libvee/logger.vala

  • Committer: Gustav Hartvigsson
  • Date: 2024-12-22 00:30:29 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241222003029-k74ogrm32zobz325
[General] Split libvee into it's own library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using Posix;
 
2
 
 
3
 
 
4
/*
 
5
 * Public Domain.
 
6
 */
 
7
 
 
8
namespace Vee {
 
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
  public class Logger {
 
17
    private const string STR_ERROR = "[ERROR]: ";
 
18
    private const string STR_INFO = "[INFO]: ";
 
19
    private unowned FILE out_file;
 
20
    
 
21
    private static Logger logger = null;
 
22
    
 
23
    public Logger (FILE out_file) {
 
24
      this.out_file = out_file;
 
25
    }
 
26
    
 
27
    public static Logger get_default () {
 
28
      if (logger == null) {
 
29
         Logger.logger = new Logger (Posix.stdout);
 
30
      }
 
31
      return logger;
 
32
    }
 
33
    
 
34
    public static void set_default (Logger logger) {
 
35
      Logger.logger = logger;
 
36
    }
 
37
    
 
38
    public void error (string str, ...) {
 
39
      out_file.printf (STR_ERROR);
 
40
      out_file.printf (str, va_list());
 
41
    }
 
42
    
 
43
    public void info (string str, ...) {
 
44
      out_file.printf (STR_INFO);
 
45
      out_file.printf (str, va_list());
 
46
    }
 
47
    
 
48
    public static void free_default () {
 
49
      Posix.free(Logger.logger);
 
50
    }
 
51
  }
 
52
}